Consider the following table STUDENT: Table: STUDENTAdmissionNo Name DOB…
2026
Consider the following table STUDENT:
Table: STUDENT
AdmissionNo | Name | DOB | ClassSec | TotalMarks |
|---|---|---|---|---|
2026103 | Sameer Jha | 2013-09-12 | 6B | 115 |
2026112 | Sonika Jain | 2014-01-08 | 6A | 406 |
2026125 | Zoya Javed | 2013-11-08 | 6A | 358 |
Note: Assume the table contains more rows following the same structure.
Write MySQL queries for the following tasks:
(A) Display all details of students who were born (DOB) in the year 2013 or earlier.
(B) Display Name, ClassSec, and TotalMarks for all students, sorted by ClassSec in ascending order. Within the same ClassSec, the details should be further sorted by TotalMarks in descending order.
(C) Display each unique ClassSec along with the total number of students in that Class Section.
(D) Display each unique ClassSec along with the average TotalMarks obtained by students in that Class Section.
Show answer & explanation
(A)
SELECT * FROM STUDENT
WHERE YEAR(DOB) <= 2013;(B)
SELECT Name, ClassSec, TotalMarks
FROM STUDENT
ORDER BY ClassSec ASC, TotalMarks DESC;(C)
SELECT ClassSec, COUNT(*) AS TotalStudents
FROM STUDENT
GROUP BY ClassSec;(D)
SELECT ClassSec, AVG(TotalMarks) AS AvgMarks
FROM STUDENT
GROUP BY ClassSec;Conclusion: SQL clauses like WHERE, ORDER BY, and GROUP BY help filter, sort, and summarize data efficiently.