mysql

sql update 时候使用left join 和groupb

2019-07-03  本文已影响0人  良人与我

这里直接备注我的demo 吧

update card_crowd  as cardCrowd
LEFT JOIN
(
select cc.id , count(1) as num
from card_crowd cc LEFT JOIN
card_crowd_r ccr on cc.id = ccr.crowd_id
group by cc.id
) as tt
on cardCrowd.id = tt.id
set cardCrowd.join_num = tt.num;

参考地址
https://stackoverflow.com/questions/3022405/mysql-update-query-with-left-join-and-group-by/56844421#56844421

上一篇 下一篇

猜你喜欢

热点阅读