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);

  

posted on 2014-04-04 14:47  jenqz  阅读(230)  评论(0编辑  收藏  举报