有student,course,choose_course 三张表,找出选了所有课程的学生名单

来源:互联网 发布:response.json 编辑:程序博客网 时间:2024/06/03 04:10
 解法1:
select sname from student s
where id in(select sid from choose_course
group by sid having count(sid)=(select count(1) from course))
解法2:
select distinct sname from student s
where not exists(
select * from course c
where not exists(
select * from choose_course cc
where cc.cid=c.id and cc.sid=s.id))
原创粉丝点击