← Back to Aggregates & GROUP BY
Question 15
Students Per Major, Undeclared Included
Students Per Major, Undeclared Included
Count the students in each major, and keep the four undeclared students as their own group. Returnmajor(the departmentname, NULL for students with no major) andstudents(the count). Sort bystudentsdescending, then bymajorascending; SQLite sorts NULL before any text, so the undeclared group comes first among the fours.
Expected result:
+------------------+----------+ | major | students | +------------------+----------+ | Computer Science | 8 | | Mathematics | 5 | | NULL | 4 | | Biology | 4 | | Business | 4 | | English | 4 | | Fine Arts | 1 | +------------------+----------+ 7 rows
Hints4 available
Sign in to use hintsTopics:
Aggregates & GROUP BY
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Ctrl+Space to expand shortcuts (sel, ins, desc)
Results
Run your SQL to see every statement's output here, then how it compares with the expected answer.
Not sure what is in a table? SHOW TABLES lists them and DESCRIBE students shows the columns — or open the database browser on the left.