使用子查询方式完成下列查询。 (1)查询“103”号课程不及格的学生学号、姓名和联系电话。 (2)查询恰好有两门课程不及格的学生信息。 (3)查询每门课程的最高分的学生记录。 (4)查询每个学生的最低分课程记录。 (5)查询每门课程的选修人数(提示:使用新增列完成)。
时间: 2024-06-10 07:05:27 浏览: 75
好的,我明白了。以下是对应问题的子查询方式查询语句:
(1)查询“103”号课程不及格的学生学号、姓名和联系电话。
```
SELECT student.id, student.name, student.phone
FROM student, score
WHERE student.id = score.s_id AND score.c_id = '103' AND score.score < 60;
```
(2)查询恰好有两门课程不及格的学生信息。
```
SELECT student.id, student.name
FROM student, score
WHERE student.id = score.s_id AND score.score < 60
GROUP BY student.id
HAVING COUNT(*) = 2;
```
(3)查询每门课程的最高分的学生记录。
```
SELECT score.c_id, student.id, student.name, MAX(score.score) as highest_score
FROM student, score
WHERE student.id = score.s_id
GROUP BY score.c_id;
```
(4)查询每个学生的最低分课程记录。
```
SELECT student.id, student.name, MIN(score.score) as lowest_score, course.name as lowest_course
FROM student, score, course
WHERE student.id = score.s_id AND score.c_id = course.id
GROUP BY student.id;
```
(5)查询每门课程的选修人数。
```
SELECT score.c_id, course.name, COUNT(*) as student_count
FROM score, course
WHERE score.c_id = course.id
GROUP BY score.c_id, course.name;
```
阅读全文