查询选修了全部课程的学生姓名
时间: 2023-11-16 20:46:53 浏览: 417
查询选修了全部课程的学生姓名的SQL语句是:
```
SELECT Sname
FROM Student
WHERE NOT EXISTS(
SELECT *
FROM Course
WHERE NOT EXISTS(
SELECT *
FROM SC
WHERE SC.Sno = Student.Sno AND SC.Cno = Course.Cno
)
);
```
这个SQL语句的含义是:查询学生表中所有选修了每门课程的学生姓名。
相关问题
SQL SEVER查询选修了课程的学生姓名。 ◇查询选修了全部课程的学生姓名。 ◇查询至少选修了学号为S01学生选修的全部课程的学生号码。 ◇查询所有存在不及格情况(<60)的学生的学号和姓名。
1. 查询选修了课程的学生姓名:
```
SELECT DISTINCT student.name
FROM student, elective
WHERE student.id = elective.id;
```
2. 查询选修了全部课程的学生姓名:
```
SELECT name
FROM student
WHERE NOT EXISTS (SELECT course_id FROM course WHERE course_id NOT IN (SELECT course_id FROM elective WHERE id = student.id));
```
3. 查询至少选修了学号为S01学生选修的全部课程的学生号码:
```
SELECT id
FROM elective
WHERE course_id IN (SELECT course_id FROM elective WHERE id = 'S01')
GROUP BY id
HAVING COUNT(DISTINCT course_id) = (SELECT COUNT(DISTINCT course_id) FROM elective WHERE id = 'S01');
```
4. 查询所有存在不及格情况(<60)的学生的学号和姓名:
```
SELECT DISTINCT student.id, student.name
FROM student, elective
WHERE student.id = elective.id AND elective.score < 60;
```
mysql查询学生所选修的全部课程_查询选修了全部课程的学生姓名
查询学生所选修的全部课程:
```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 子句来筛选选修了全部课程的学生。
阅读全文