【sql: 练习题19 ,20】查询每门课程被选修的学生数,查询出只选修两门课程的学生学号和姓名
题目 19:查询每门课程被选修的学生数
SELECT courseid,COUNT(studentid) FROM student_score GROUP BY courseid;
运行:
练习题20 :查询出只选修两门课程的学生学号和姓名
SELECT student.*, r.a FROM student,
(SELECT studentid,COUNT(courseid) AS a FROM student_score GROUP BY student_score.studentid)r
WHERE r.a =2 AND student.id = r.studentid ;
运行: