【sql 练习题 38 ,39】检索至少选修两门课程的学生学号,查询选修了全部课程的学生信息

题目38:检索至少选修两门课程的学生学号

 

SELECT studentid ,COUNT(courseid) AS a
FROM student_score GROUP BY studentid HAVING a >=2

 

 

 

 

题目39:查询选修了全部课程的学生信息

GROUP BY studentid 然后count(score)=全部课程数

 

 

SELECT student.* FROM student,
(SELECT studentid,COUNT(courseid) AS a FROM student_score GROUP BY studentid
HAVING a = (SELECT COUNT(*) FROM student_course))r WHERE student.id = r.studentid

 

 

 

posted @ 2019-08-19 17:08  初学者,方圆几里  阅读(10609)  评论(0编辑  收藏  举报