select distinct
pos.DivNo
,WeekOfYear
,[ProductCode]
,sum(Quantity)[Quantity]
into #sales1
from cbis799p.dbo.pos pos
LEFT JOIN DataWarehouse.dbo.Calendar c on pos.PosDate = c.Datetime
Where pos.DivNo = 772 and ProductCode = '1020'
and WeekOfYear = 1
and YearWeek = 2015
group by pos.DivNo
,WeekOfYear
,[ProductCode]
select * from #sales1
drop table #sales1
select distinct
pos.DivNo
,Min(WeekOfYear) WeekOfYear
,[ProductCode]
,SUM(quantity) PreQuantity
into #sales2
from cbis799p.dbo.pos pos
LEFT JOIN DataWarehouse.dbo.Calendar c on pos.PosDate = c.Datetime
where pos.DivNo = 772 and ProductCode = '1020'
and WeekOfYear = 1
and YearWeek = 2015
group by pos.DivNo
,WeekOfYear
,[ProductCode]
select * from #sales2
drop table #sales2
这是我的输出 我需要优先来自一周 - 一周 这将使它成为2014年的第52周
我需要动态调整这个值,以便参数可以理解