SQL查询2门以上课程成绩不低于80分的学生的学号、以及不低于85分的课程的门数。
展开全部
您好:
您这个需求有点复杂,时间缘故没有测试。
如果有异常,请联系我,我回家重新给您看看。
以下是SQL代码
SELECT Student.sno,(SELECT COUNT(*) FROM grade g WHERE g.sno=Student.sno AND grade>=85 )
FROM Student
LEFT JOIN Score ON Score.sno=Student.sno
LEFT JOIN Course ON Course.cno=Score.cno
WHERE grade>=80
GROUP BY Student.sno
HAVING COUNT(*)>2
您这个需求有点复杂,时间缘故没有测试。
如果有异常,请联系我,我回家重新给您看看。
以下是SQL代码
SELECT Student.sno,(SELECT COUNT(*) FROM grade g WHERE g.sno=Student.sno AND grade>=85 )
FROM Student
LEFT JOIN Score ON Score.sno=Student.sno
LEFT JOIN Course ON Course.cno=Score.cno
WHERE grade>=80
GROUP BY Student.sno
HAVING COUNT(*)>2
更多追问追答
追问
不行,FROM grade g 是什么意思?
追答
处理你那个不低于85分的门数,做一个相关子查询
你不着急的话,我晚点把你的数据录进去试试。
盲写有时候会有点问题的,抱歉。
SELECT Student.sno,(SELECT COUNT(*) FROM Score g WHERE g.sno=Student.sno AND grade>=85 )
FROM Student
LEFT JOIN Score ON Score.sno=Student.sno
LEFT JOIN Course ON Course.cno=Score.cno
WHERE grade>=80
GROUP BY Student.sno
HAVING COUNT(*)>=2
我很郁闷,我把整个表录入一遍,发现就是
FROM grade g
这里出现了低级错误应该为
FROM Score g
这是查询结果,请查收
展开全部
select std.sno,count(1) from Student std,Score s where s.grade >= 85 and std.sno in
(select sno from Score s where s.grade >= 80 and s.sno=std.sno group by s.sno having count(1) > 1) group by std.sno;
我没试过啊 你试一试
追问
错啦,全都是11
追答
= = 哈哈
select std.sno,count(s.sno) from Student std,Score s where s.grade >= 85 and std.sno=s.sno and std.sno in
(select sno from Score s where s.grade >= 80 group by s.sno having count(1) > 1) group by std.sno;
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询