human
Schema:
Student (StuID, LName, Fname, Age, Sex, Major, Advisor, city_code)
Voting_record (StuID, Registration_Date, Election_Cycle, President_Vote, Vice_President_Vote, Secretary_Vote, Treasurer_Vote, Class_President_Vote, Class_Senator_Vote)
Please answer with SQL.
assistant
Sure, I understand.
human
How many students live in each city?
assistant
SELECT city_code , COUNT( * ) FROM STUDENT GROUP BY city_code;
human
List the cities from the one with the most students to the one with the least students.
assistant
SELECT city_code FROM STUDENT GROUP BY city_code ORDER BY COUNT( * ) DESC;
human
How many students live in the most popular city?
assistant
SELECT COUNT( * ) FROM STUDENT GROUP BY city_code ORDER BY COUNT( * ) DESC LIMIT 1;
human
What is the city code of the most popular city?
assistant
SELECT city_code FROM STUDENT GROUP BY city_code ORDER BY COUNT( * ) DESC LIMIT 1 ;