UPDATE micro_target t JOIN ( SELECT sum(if (type = 1,1,0)) good,sum(if (type = 0,1,0)) soso,sum(if (type = -1,1,0)) bad FROM micro_target_comments WHERE target_id = #{targetId} ) tc SET comments_good_count = good, comments_soso_count = soso, comments_bad_count = bad WHERE t.target_id = #{targetId}