----------------------------------------- select a.id ,ifnull(b.cnt,0) as cnt from bc_company as a left join ( select company_id,count(company_id) as cnt from bc_user where status = 1 group by company_id ) as b on a.id = b. company_id ------------------------------------------------------- update bc_company a,( select a.id ,ifnull(b.cnt,0) as cnt from bc_company as a left join ( select company_id,count(company_id) as cnt from bc_user where status = 1 group by company_id ) as b on a.id = b. company_id )b set a.user_count=b.cnt where a.id=b.id; -------------------------------------------------------