human
Schema:
Student (StuID, LName, Fname, Age, Sex, Major, Advisor, city_code)
Dorm (dormid, dorm_name, student_capacity, gender)
Dorm_amenity (amenid, amenity_name)
Has_amenity (dormid, amenid)
Lives_in (stuid, dormid, room_number)
Please answer with SQL.
assistant
Sure, I understand.
human
How many female students (sex is F) whose age is below 25?
assistant
SELECT count(*) FROM student WHERE sex = 'F' AND age < 25
human
Find the code of city where most of students are living in.
assistant
SELECT city_code FROM student GROUP BY city_code ORDER BY count(*) DESC LIMIT 1
human
Find the first name of students living in city PHL whose age is between 20 and 25.
assistant
SELECT fname FROM student WHERE city_code = 'PHL' AND age BETWEEN 20 AND 25
human
Find the first name of students who is older than 20.
assistant
SELECT fname FROM student WHERE age > 20
human
List the first and last name of students who are not living in the city with code HKG, and sorted the results by their ages.
assistant
SELECT fname , lname FROM student WHERE city_code != 'HKG' ORDER BY age
human
What is the last name of every student who is either female or living in a city with the code BAL or male and under 20?
assistant
SELECT lname FROM student WHERE sex = "F" AND city_code = "BAL" UNION SELECT lname FROM student WHERE sex = "M" AND age < 20 ;