第一想法:
從分數表里面把小於60的學生id都查出來。
SELECT tblstudent.StuId,tblstudent.StuName FROM tblstudent WHERE
(
SELECT tblscore.Score FROM tblscore WHERE tblstudent.StuId=tblscore.StuId AND tblscore.Score<60
)
然后報錯:
Subquery returns more than 1 row
是的呀。
SELECT tblscore.Score FROM tblscore WHERE tblstudent.StuId=tblscore.StuId AND tblscore.Score<60這句話查出來的數據有好幾條呢。這樣的當然是不對的。
還是不知道怎么修改,於是看答案:
select tblstudent.StuId,tblstudent.StuName from tblstudent where tblstudent.StuId NOT IN ( select tblscore.StuId from tblscore where tblstudent.StuId=tblscore.StuId AND tblscore.Score>60)