查询选修了课程的学生姓名。
时间: 2023-11-24 20:50:24 浏览: 102
学生选修课查询系统
以下是两种查询选修了课程的学生姓名的SQL语句:
1.使用NOT EXISTS子查询:
```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
)
);
```
2.使用COUNT(*)和GROUP BY子句:
```sql
SELECT Sname
FROM Student
WHERE Sno IN (
SELECT Sno
FROM SC
GROUP BY Sno
HAVING COUNT(*) = (
SELECT COUNT(*)
FROM Course
)
);
```
阅读全文