sql找出选修了所有课程的学生号
时间: 2023-12-07 12:02:38 浏览: 146
根据提供的引用内容,有三种方法可以找出选修了所有课程的学生号:
方法一:使用子查询
```
SELECT sno FROM student WHERE sno NOT IN (SELECT sno FROM sc WHERE cno <> '1');```
方法二:使用EXISTS关键字
```
SELECT sno FROM student WHERE NOT EXISTS (SELECT * FROM course WHERE NOT EXISTS (SELECT * FROM sc WHERE sc.sno = student.sno AND sc.cno = course.cno));
```
方法三:使用INNER JOIN
```
SELECT s.sno FROM student s INNER JOIN sc ON s.sno = sc.sno GROUP BY s.sno HAVING COUNT(DISTINCT sc.cno) = (SELECT COUNT(*) FROM course);
```