需要使用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
时间: 2024-10-13 21:57:52