50個查詢系列-第9個查詢:查詢所有課程成績小於60分的同學的學號、姓名;


第一想法:

從分數表里面把小於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)

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM