mysql关联更新表

UPDATE ecm_store s LEFT JOIN (SELECT store_id, COUNT(goods_id) AS goods_count FROM ecm_goods GROUP BY store_id) gc ON s.store_id = gc.store_id 

SET s.goods_count = IF(gc.goods_count IS NULL, 0, gc.goods_count);

  

你可能感兴趣的:(mysql)