
mysql left join 实现多条数据中某字段最大值的更新
在mysql中,对于更新student表中score字段的值,使其等于score表中对应student_id的最大值,可以使用以下方法:
查询语句:
update student set score=(select max(score) from score where score.student_id=student.id)
解释:
left join: 将student表和score表以student_id列进行连接,对于student表中的每一行,找出score表中对应的最大score值。max(score): 获取得分表中特定学生得分的最大值。where score.student_id=student.id: 确保score表的student_id与student表的student_id匹配。update student set score=(): 将student表的score字段更新为从( )中选出的最大值。
执行此查询后,student表中每个学生的score字段将更新为他们在score表中获得的最高分数。
以上就是如何使用MySQL left join 更新学生表中成绩字段为对应学生在成绩表中的最高分?的详细内容,更多请关注创想鸟其它相关文章!
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 chuangxiangniao@163.com 举报,一经查实,本站将立刻删除。
发布者:程序猿,转转请注明出处:https://www.chuangxiangniao.com/p/41594.html
微信扫一扫
支付宝扫一扫