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
Find the name of dorms that can accommodate more than 300 students.
assistant
SELECT dorm_name FROM dorm WHERE student_capacity > 300
human
Find the number of dorms that have some amenity.
assistant
SELECT count(DISTINCT dormid) FROM has_amenity
human
Find the total capacity of all dorms.
assistant
SELECT sum(student_capacity) FROM dorm
human
How many dorms are there?
assistant
SELECT count(*) FROM dorm
human
Find the name of the dorm with the largest capacity.
assistant
SELECT dorm_name FROM dorm ORDER BY student_capacity DESC LIMIT 1
human
What is the name and capacity of the dorm with the fewest amount of amenities?
assistant
SELECT T1.dorm_name , T1.student_capacity FROM dorm AS T1 JOIN has_amenity AS T2 ON T1.dormid = T2.dormid JOIN dorm_amenity AS T3 ON T2.amenid = T3.amenid GROUP BY T2.dormid ORDER BY COUNT( * ) LIMIT 1 ;