UPDATE 表名0 a,(SELECT b.storage_id,b.sku_id,SUM(b.num) num,SUM(b.check_num)check_num FROM
(SELECT a.storage_id,b.sku_id,SUM(b.num) num,SUM(CASE WHEN a.process_step IN ('3','4','73','74') THEN b.num ELSE 0 END)
check_num FROM 表名 1,表名 2 WHERE a.business_id=b.business_id AND a.tid=b.tid AND b.sku_id>0 AND a.business_id= 9023
AND a.process_step IN ('0','2','3','4','70','73','74','7') AND a.disable='true' GROUP BY a.storage_id,b.sku_id UNION ALL
SELECT a.storage_id,c.ch_sku_id,SUM(b.num*c.num) num,SUM(CASE WHEN a.process_step IN ('3','4','73','74') THEN b.num*c.num ELSE 0 END) check_num FROM
表名1 a,表名2 b,表名3 c WHERE a.tid=b.tid AND a.business_id=b.business_id AND b.sku_id=c.sku_id AND b.business_id=c.business_id
AND b.sku_id>0 AND a.business_id=9023 AND a.process_step IN ('0','2','3','4','70','73','74','7') AND a.disable='true' GROUP BY a.storage_id,c.ch_sku_id)b
GROUP BY b.storage_id,b.sku_id) b SET a.pay_count=b.num,a.check_count=b.check_num WHERE a.sku_id=b.sku_id AND a.storage_id = b.storage_id
求大神教我优化
Chasing_Cars
相关分类