Question: Find the first name of students who are living in the dorm that has most number of amenities.
Schema: create table dorm_amenity (amenid varchar, PRIMARY KEY (amenid)); create table lives_in (stuid varchar, dormid varchar, PRIMARY KEY (stuid)); create table dorm (dormid varchar, PRIMARY KEY (dormid)); create table student (fname varchar, stuid varchar, PRIMARY KEY (fname)); create table has_amenity (dormid varchar, amenid varchar, PRIMARY KEY (dormid))
SQL: select t1.fname from student as t1 join lives_in as t2 on t1.stuid = t2.stuid where t2.dormid in (select t2.dormid from dorm as t3 join has_amenity as t4 on t3.dormid = t4.dormid join dorm_amenity as t5 on t4.amenid = t5.amenid group by t3.dormid order by count(*) desc limit 1)