我們來說一下思路:
1:先找所開的所有的課程
2.在遍歷每一個學,看在學生的課表里面是不是都有這些課,有的話說明全選了,沒有的話就是沒有全選。用NOT IN
這里的not in 和IN 有區別,我剛開始用 notexists in不行,后來用了exists not in 就好了。查出來的結果都不一樣。
select tblstudent.StuName,tblstudent.StuId from tblstudent where EXISTS ( select * from (SELECT tblcourse.CourseId t1 FROM tblcourse)t-- t1是全部的課程 where t.t1 not IN-- 全部的課程在學生上的課程里面都不存在那就說明學生沒有選滿全部的課,因為如果學生選了全部的課程,在學生的課表里就能找到所有的課 (select tblscore.CourseId from tblscore where tblstudent.StuId=tblscore.StuId))
答案的做法是:
Select StuId,StuName From tblStudent st Where (Select Count(*) From tblScore sc Where st.StuId=sc.StuId)< (Select Count(*) From tblCourse)