本站资源收集于互联网,不提供软件存储服务,每天免费更新优质的软件以及学习资源!

MySQL如何用LEFTJOIN更新学生表中每个学生的最高成绩?

网络教程 app 1℃

MySQL如何用LEFTJOIN更新学生表中每个学生的最高成绩

如何在 mysql 中使用 left join 更新多个结果中的最大值?

问题:

已知以下 two tables:

student 表:

| id | name ||—|—|| 1 | 小明 || 2 | 小红 |

score 表:

| id | student_id | score ||—|—|—|| 1 | 1 | 80 || 2 | 2 | 88 || 3 | 1 | 78 || 4 | 2 | 98 |

如何使用 mysql 更新 student 表中每个学生的 score 字段为 score 表中对应学生成绩的最高分?

答案:

update student set score=(select max(score) from score where score.student_id=student.id)

以上就是MySQL如何用LEFT JOIN更新学生表中每个学生的最高成绩?的详细内容,更多请关注范的资源库其它相关文章!

转载请注明:范的资源库 » MySQL如何用LEFTJOIN更新学生表中每个学生的最高成绩?

喜欢 (0)