发布网友 发布时间:2022-04-09 15:11
共5个回答
懂视网 时间:2022-04-09 19:32
如下语句如果不加go的话,当做一个批处理编译时会报错,提示没有split_count和split_amount列。加了go时可以一起执行
--3.Kit split in sale_detail: split_count,split_amount
ALTER TABLE sale_detail ADD split_count INT,split_amount float
go
--EXECUTE TIME 40 minute
UPDATE ssd SET ssd.split_count=tt.split_count,ssd.split_amount=tt.split_amount
FROM dbo.sale_detail ssd
JOIN (
SELECT a.rid,SUM(ISNULL(a.split_units,0)) AS split_count,SUM(ISNULL(a.split_rmb,0)) AS split_amount
FROM (
SELECT sd.rid, SUM(( CASE WHEN pk.count IS NULL THEN 1 ELSE pk.count END ) * sd.count) AS split_units,
SUM(CASE WHEN pk.price IS NULL THEN sd.amount ELSE pk.price * pk.count * sd.count END ) AS split_rmb
FROM sale_detail sd WITH(NOLOCK)
LEFT JOIN product p WITH(NOLOCK) ON p.product_id = sd.product_id
LEFT JOIN product_kit pk WITH(NOLOCK) ON pk.kit_id = p.product_id
AND pk.status = 0
AND sd.sale_date >= pk.start_date
AND sd.sale_date <= pk.end_date
WHERE sd.status = 0
AND p.status <> 1
AND p.ispromotion = 0
GROUP BY sd.rid
) a
GROUP BY a.rid
) tt ON ssd.rid = tt.rid
SQL语句是以一个patch为单位编译
标签:with from time date ice 处理 group by cas set
热心网友 时间:2022-04-09 16:40
--我给的这个答案是在ID可能不连续的情况下,让相邻的两个ID上的值大号减小号。 caidchelp写的语句在ID是连续的,并且ID递增为一的情况下也是正确的。热心网友 时间:2022-04-09 17:58
--首先建一张t_zbxx_sum表,字段为本期累计和保存时间,用于存放结果热心网友 时间:2022-04-09 19:33
select a.保存时间,a.本期累计-max(b.本期累计)热心网友 时间:2022-04-09 21:24
123456