MySQL设计程序题
黄鸭 3/13/2022 server
# 1.请写出SQL查询语句
已知基本表结构如下
- student (id, name, age, gender) 学生表
- teacher (id, name) 教师表
- course (id, name, teacher_id) 课程表
- score (id, student_id, course_id, score) 成绩表
请写出SQL查询语句:
- 查询所有同学的学生编号、学生姓名、选课总数、所有课程的总成绩。
- 查询平均成绩大于等于60分的同学的学生编号和学生姓名和平均成绩。
查看答案
select
student.id,student.name,count(score.id),sum(score.score)
from student,course,score
where student.id = course.student_id and student.id = score.course_id
order by student.id
select
student.id,student.name,avg(score.score) avgscore
from student,course,score
where student.id = course.student_id and student.id = score.course_id
order by student.id having avgscore>=60
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11