mysql在update时,从其他select结果集更新表

需要使用join,例如

select g.id,g.res_count,count(gr.r_id) cnt from mb_game_res gr left join mb_game g on gr.g_id = g.id group by gr.g_id order by cnt desc
update mb_game a left join (select g.id id,count(gr.r_id) cnt from mb_game_res gr left join mb_game g on gr.g_id = g.id group by gr.g_id) b on a.id = b.id set a.res_count = b.cnt

原文地址:https://www.cnblogs.com/kudosharry/p/3946666.html