【发布时间】:2015-08-21 12:39:09
【问题描述】:
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
这是我的输出 我需要从一年中的一周来的前量 - 1周 这将使它成为 2014 年的第 52 周
我需要这个值是动态的,以便参数可以理解
【问题讨论】:
-
@lad2025 这只是要告诉我 2 天之间的差异
-
用户也想搜索一年中的一周作为参数
-
我不明白这个问题。是否有某些原因 DATEADD() 不是答案?
标签: sql-server visual-studio week-number product-quantity