#like count
update vt_blast b inner join (SELECT blast_id, count(*) as total FROM vt_blast_like group by blast_id) t ON t.blast_id = b.id set b.like_count = t.total;
#comment count
update vt_blast b inner join (SELECT blast_id, count(*) as total FROM vt_blast_comment where is_active = 1 group by blast_id) t ON t.blast_id = b.id set b.comment_count = t.total;
# fan count
update vt_user b inner join (SELECT star_id, count(*) as total FROM vt_fan group by star_id) t ON t.star_id = b.id and b.user_type='STAR' set b.fan_count = t.total;
# week fan count
update vt_user b inner join (SELECT star_id, count(*) as total FROM vt_fan WHERE created_at > date_add(now(), '-7 day') group by star_id) t ON t.star_id = b.id and b.user_type='STAR' set b.week_fan_count = t.total;
Title:
MySQL - Update count with inner join
Description:
#like count update vt_blast b inner join (SELECT blast_id, count(*) as total FROM vt_blast_like group by blast_id) t ON t.blast_id = b.id s...
...
Rating:
4