← Back to CTEs
Question 43
Cities With at Least Three Students
Cities With at Least Three Students
Count the students in eachcityinside a CTE namedper_city(columnscityandstudents), then selectcityandstudentsfrom it for the cities with three or more students. Sort bystudentsdescending, thencity.
Expected result:
+-------------+----------+ | city | students | +-------------+----------+ | Toronto | 8 | | Ottawa | 5 | | Hamilton | 4 | | Mississauga | 4 | | Kingston | 3 | | London | 3 | +-------------+----------+ 6 rows
Hints3 available
Sign in to use hintsTopics:
CTEs
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.