sql查询选修C语言课程的成绩高于电子学所有成绩的学生的学号和成绩
时间: 2024-10-10 10:05:53 浏览: 68
在SQL中,如果你想要找到选修了C语言课程并且成绩高于所有电子学课程成绩的学生的学号和成绩,可以使用以下查询,假设我们有两个表:一个是学生信息表(students),另一个是课程成绩表(courses_scores):
```sql
SELECT st.student_id, cs.score
FROM students st
JOIN courses_scores cs ON st.student_id = cs.student_id
JOIN (
SELECT course_name, MAX(score) as max_score
FROM courses_scores
WHERE course_name = 'C语言'
GROUP BY student_id
) cmax ON cs.course_name = 'C语言' AND cs.score > cmax.max_score
WHERE cs.course_name = 'C语言';
```
这个查询做了以下几件事:
1. 使用JOIN将学生表和成绩表关联起来。
2. 在子查询(cmax)中找到每位学生在"C语言"课程下的最高成绩。
3. 主查询中筛选出那些在"C语言"课程中的成绩超过该学生最高C语言成绩的学生。
4. 最后只返回他们的学号(student_id)和成绩(score)。
阅读全文
相关推荐
















