您好,欢迎来到爱玩科技网。
搜索
您的当前位置:首页50个查询系列-第9个查询:查询所有课程成绩小于60分的同学的学号、姓名;

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)

 

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- aiwanbo.com 版权所有 赣ICP备2024042808号-3

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务