1.查询所有未选修过课程的学生的学号和姓名 2.查询所有比“计算机”专业学生平均分高的学生姓名、学号 3.查询所有比“王敏”总学分高的学生姓名、学号 4.查询比所有“计算机”专业学生学分高的学生姓名、学号 5.查询所有不比“计算机”专业学生学分低的学生姓名、学号
时间: 2023-11-16 18:19:10 浏览: 200
好的,我会分别为您回答这五个问题。
1. 查询所有未选修过课程的学生的学号和姓名:
```
SELECT id, name FROM students WHERE id NOT IN (SELECT student_id FROM course_selections);
```
2. 查询所有比“计算机”专业学生平均分高的学生姓名、学号:
```
SELECT s.id, s.name FROM students s, course_selections cs WHERE s.id = cs.student_id AND cs.score > (SELECT AVG(cs1.score) FROM course_selections cs1, courses c WHERE c.id = cs1.course_id AND c.major = '计算机');
```
3. 查询所有比“王敏”总学分高的学生姓名、学号:
```
SELECT s.id, s.name FROM students s, course_selections cs WHERE s.id = cs.student_id GROUP BY s.id HAVING SUM(cs.credit) > (SELECT SUM(cs1.credit) FROM students s1, course_selections cs1 WHERE s1.name = '王敏' AND s1.id = cs1.student_id);
```
4. 查询比所有“计算机”专业学生学分高的学生姓名、学号:
```
SELECT s.id, s.name FROM students s, course_selections cs WHERE s.id = cs.student_id GROUP BY s.id HAVING SUM(cs.credit) > (SELECT SUM(cs1.credit) FROM course_selections cs1, courses c WHERE c.major = '计算机' AND cs1.course_id = c.id GROUP BY cs1.student_id ORDER BY SUM(cs1.credit) DESC LIMIT 1);
```
5. 查询所有不比“计算机”专业学生学分低的学生姓名、学号:
```
SELECT s.id, s.name FROM students s, course_selections cs WHERE s.id = cs.student_id GROUP BY s.id HAVING SUM(cs.credit) >= (SELECT SUM(cs1.credit) FROM course_selections cs1, courses c WHERE c.major = '计算机' AND cs1.course_id = c.id GROUP BY cs1.student_id ORDER BY SUM(cs1.credit) DESC LIMIT 1);
```
以上是查询语句,具体实现可能还需要根据您的数据库表结构进行稍微修改。
阅读全文