What are the names of all the dorms?
select dorm_name from dorm
Which of those dorms have a TV Lounge?
select t1.dorm_name from dorm as t1 join has_amenity as t2 on t1.dormid = t2.dormid join dorm_amenity as t3 on t2.amenid = t3.amenid where t3.amenity_name = 'TV Lounge'
Yes.
select t1.dorm_name from dorm as t1 join has_amenity as t2 on t1.dormid = t2.dormid join dorm_amenity as t3 on t2.amenid = t3.amenid where t3.amenity_name = 'TV Lounge' except select t1.dorm_name from dorm as t1 join has_amenity as t2 on t1.dormid = t2.dormid join dorm_amenity as t3 on t2.amenid = t3.amenid where t3.amenity_name = 'Study Room'
And the gender that is housed?
select t1.dorm_name,t1.gender from dorm as t1 join has_amenity as t2 on t1.dormid = t2.dormid join dorm_amenity as t3 on t2.amenid = t3.amenid where t3.amenity_name = 'TV Lounge' except select t1.dorm_name,t1.gender from dorm as t1 join has_amenity as t2 on t1.dormid = t2.dormid join dorm_amenity as t3 on t2.amenid = t3.amenid where t3.amenity_name = 'Study Room'
For this dorm.
select t1.dorm_name,t3.amenity_name from dorm as t1 join has_amenity as t2 on t1.dormid = t2.dormid join dorm_amenity as t3 on t2.amenid = t3.amenid where t1.dorm_name = 'Fawlty Towers'