mysql left join 实现多条数据中某字段最大值的更新
在mysql中,对于更新student表中score字段的值,使其等于score表中对应student_id的最大值,可以使用以下方法:
查询语句:
update student set score=(select max(score) from score where score.student_id=student.id)
解释:
tudent_id=student.id: 确保score表的student_id与student表的student_id匹配。执行此查询后,student表中每个学生的score字段将更新为他们在score表中获得的最高分数。