mysql查询学生所选修的全部课程_查询选修了全部课程的学生姓名
时间: 2023-11-15 17:05:08 浏览: 163
毕设&课程作业_基于C#的、MySQL 学生选修课管理系统.zip
查询学生所选修的全部课程:
```mysql
SELECT s.name, c.course_name
FROM student s
JOIN student_course sc ON s.id = sc.student_id
JOIN course c ON sc.course_id = c.id
WHERE s.id = [学生ID];
```
查询选修了全部课程的学生姓名:
```mysql
SELECT s.name
FROM student s
JOIN student_course sc ON s.id = sc.student_id
JOIN course c ON sc.course_id = c.id
GROUP BY s.id
HAVING COUNT(DISTINCT c.id) = (SELECT COUNT(*) FROM course);
```
这里使用了子查询来获取全部课程的数量,再通过 GROUP BY 和 HAVING 子句来筛选选修了全部课程的学生。
阅读全文