更新A表中的属性数学成绩,筛选条件是A表的学号等于C表的学号,将A表的数学成绩更新为B表中学号为刚刚筛选条件的数学成绩的求和,其中,B表和C表的学生数据一一对应,给出mysql语句
时间: 2023-05-26 19:01:57 浏览: 42
UPDATE A
SET math_score = (
SELECT SUM(B.math_score)
FROM B
INNER JOIN C ON B.student_id = C.student_id
WHERE C.student_id = A.student_id
)
WHERE A.student_id IN (
SELECT student_id
FROM C
)
相关问题
更新A表中的属性数学成绩,筛选条件是A表的学号等于B表的学号,将A表的数学成绩更新为B表中学号为刚刚筛选条件的数学成绩的求和,给出mysql语句
UPDATE A
SET math_score = (SELECT SUM(math_score)
FROM B
WHERE A.student_id = B.student_id)
WHERE A.student_id IN (SELECT student_id FROM B);
求选修数学课且成绩为90分以上的学生学号、姓名、及成绩。
假设有三张表:学生表(students)、课程表(courses)和成绩表(scores),其中数学课的课程编号为"001",则可以使用以下 SQL 语句查询选修数学课且成绩为90分以上的学生学号、姓名、及成绩:
```
SELECT
students.student_id,
students.student_name,
scores.score
FROM
students
INNER JOIN scores ON students.student_id = scores.student_id
INNER JOIN courses ON scores.course_id = courses.course_id
WHERE
courses.course_id = '001' AND scores.score >= 90;
```
其中,使用 INNER JOIN 连接三张表,将学生表、成绩表和课程表进行关联,再用 WHERE 子句筛选出选修数学课且成绩为90分以上的记录,最后用 SELECT 子句选择需要查询的字段,即可得到学生的学号、姓名、及成绩。
相关推荐
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)