描述:已知student表有姓名-name,分数-grade,课程-course,它们多对多对多,一条sql语句查询每门课程都大于80分的学生姓名?
分析:
①每门课程,涉及到课程数量统计
SELECT COUNT(DISTINCT(s.course),s.course) courseCount FROM student s
②课程大于80分的学生
select s1.name,count(grade) from student s1 where s1.grade>80 group by s1.name
③每门课程都大于80分的学生
SELECTs2.NAME FROM( SELECT s1.NAME, count( grade ) moreThan80Count FROM student s1 WHERE s1.grade > 80 GROUP BY s1.NAME ) s2 WHEREs2.moreThan80Count =(SELECTCOUNT( DISTINCT ( s.course ), s.course ) courseCount FROMstudent s)
如果觉得《数据库:一条sql语句查询每门课程都大于80分的学生姓名》对你有帮助,请点赞、收藏,并留下你的观点哦!