SQL-Query
SQL-Query
sql>
Sql> SELECT std_name
FROM student
WHERE marks > 80;
7. Retrieve students who have marks less than the average marks of the entire class.
Sql>SELECT student_name
FROM student
WHERE marks < (SELECT AVG(marks) FROM student_records);
14. Retrieve the minimum marks achieved in the entire student table.
Sql>SELECT MIN(marks) AS “minimum_marks”
FROM student_records;
16. Count how many students received marks higher than the average.
Sql>SELECT COUNT(*) AS “students_above_average”
FROM student
WHERE marks > (SELECT AVG(marks) FROM student);
20. Calculate the difference between the highest and lowest marks in the class.
Sql>SELECT MAX(marks) - MIN(marks) AS “Marks_Difference”
FROM student;
21. Find students who scored more than 10% above the average marks.
Sql>SELECT std_name, marks
FROM student
WHERE marks > (SELECT AVG(marks) * 1.10 FROM student);
23. Calculate the average marks and round it to two decimal places.
Sql>SELECT ROUND(AVG(marks), 2) AS “average_marks”
FROM student;
24. Determine the percentage contribution of each student's marks to the total marks.
Sql>SELECT std_name, marks, (marks / (SELECT SUM(marks) FROM student) * 100) AS
“percentage_contribution”
FROM student;
25. Get the absolute difference between each student’s marks and the average marks.
Sql>SELECT stt_name, marks, ABS(marks - (SELECT AVG(marks) FROM student))
AS “marks_difference”
FROM student;
26. Find the rank of each student based on their marks using a window function (if supported by
your SQL dialect).
Sql>SELECT std_name, marks, RANK() OVER (ORDER BY marks DESC) AS rank
FROM student;
.
27. Counts the total number of students in the table.
Sql>SELECT COUNT(*) AS “total_students” FROM students;
31. Extracts the first two letters of each student's first name.
Sql>SELECT std_name, SUBSTRING(std_name, 1, 2) AS “first_two_letters” FROM students;
32. Retrieves all students whose names start with the letter 'S'.
Sql>SELECT * FROM student
WHERE std_name LIKE 'S%';
33. Retrieves students whose names have more than four characters.
Sql>SELECT * FROM students
WHERE LENGTH(first_name) > 3;
35. Adds a new column email to the students table to store email addresses.
Sql>ALTER TABLE student
ADD email VARCHAR(100);
38. Sets the student_id column as the primary key for the table.
Sql>ALTER TABLE students
ADD PRIMARY KEY (student_id);
39. Ensures that all values in the email column are unique.
Sql>ALTER TABLE students
ADD CONSTRAINT unique_email UNIQUE (email);
42. Sets a default marks of 80 for any students whose marks is currently null.
Sql>UPDATE student
SET grade = 80
WHERE marks IS NULL;
46. Removes all records from the students table but keeps the table structure intact.
Sql>DELETE FROM students;
47. Retrieves all columns and records from the students table.
Sql>SELECT * FROM students;
48. Retrieves only the first_name and last_name columns for all students.
Sql>SELECT first_name, last_name FROM students;
50. Retrieves all students whose marks are greater than 80.
Sql>SELECT * FROM student
WHERE marks > 80;
54. Groups students by their subject and counts how many students are in each subject.
Sql>SELECT marks, COUNT(*) AS “Totakl Student”
FROM students
GROUP BY marks;
56. Finds all students whose first name starts with the letter 'A'.
Sql>SELECT * FROM students
WHERE std_name LIKE 'A%';
57. Retrieves students whose marks are above the average marks.
Sql>SELECT * FROM student
WHERE marks > (SELECT AVG(marks) FROM student);