-1

我有 3 个如下所示的表:

STUDENT(*snum: integer, sname: string, deptid: integer, slevel: string, age: integer)

CLASS(*cname: string, meets_at: date, room: string, fid: integer)

ENROLLED(*snum: integer, *cname: string)

我正在尝试查找所有房间(CLASS 中的房间)都有课程的学生的学生姓名(sname)。我该怎么做呢?

4

1 回答 1

1
select sname from STUDENT
join ENROLLED on STUDENT.snum = ENROLLED.snum
join CLASS on ENROLLED.cname = CLASS.cname
group by sname
having count(distinct room) = (select count(distinct room) from CLASS)

SQLfiddle在这里:http ://sqlfiddle.com/#!2/71cba/1/0

您可能应该将 ROOMS 作为一个单独的表,以避免房间名称输入不一致的问题。

于 2012-10-18T03:01:59.780 回答