mysql使用left join更新表中多條數據中的最大值
問題:
如何將student表中score字段更新為對應score表中最大值的score?
數據結構:
- student表:id、name、score
- score表:id、student_id、score
update student set score=(select max(score) from score where score.student_id=student.id)
說明:
該sql語句使用left join連接student表和score表,根據student.id和score.student_id字段進行匹配。對于每個student表中的記錄,它會從score表中獲取關聯的score值的列表,然后使用max()函數計算列表中的最大值。最后,將最大值更新到student表的score字段。
? 版權聲明
文章版權歸作者所有,未經允許請勿轉載。
THE END