S(studentid,name) studentid,name分别代表学号,学员姓名
C(classid,classname) classid,classname分别代表课程编号,课程名称
SC(studentid,classid) studnetid,classid分别代表学号,所选修的课程编号
查询选修全部课程的学员姓名
用一条SQL语句查出来
我已经用一种方法查出来了 但总感觉不好
select s.name from S s where s.studentid in ( select a from (select sc.studentid a,count(sc.classid) b from SC sc group by sc.studentid) p where p.b=(select count(*) from C))
不知道各位大哥还有什么别的方法没
问题补充:
感谢 backlove 的回答,让我羞愧不已, having 我居然忘记了 -。-!
但 backlove 的方法还是和我的思路一样,都是拿有几条课程数来比较的,不知道除了这种方法外还有别的方法没?
select * from s where studentid in (select studentid from sc group by studentid having count(*)=(select count(*) from c))
暂时没啥新思路,解决问题就行了,这种问题没必要深究
http://samung.iteye.com/blog/289339
要验证sql执行效益 在oracle环境下的