SELECT
CAST(CONVERT(varchar, W.CreateTS, 101)AS SMALLDATETIME) AS [SoldDate]
,COUNT(*) AS NumberOfWidgets
,FT.FormName
FROM tblWidget W
JOIN tblFormType FT ON (W.FormTypeID = FT.FormTypeID)
WHERE W.CreateTS >= DATEADD(YEAR, -1, @RunDate)
GROUP BY CAST(CONVERT(varchar, W.CreateTS, 101)AS SMALLDATETIME), FT.FormName
当前的代码汇总了每天销售的小部件数量,并且可以追溯到第1天。我需要知道每7天售出多少。
任何帮助都会很棒。
答案 0 :(得分:2)
SELECT
DATEPART(week, w.CreateTS) AS [SoldWeek]
,COUNT(*) AS NumberOfWidgets
,FT.FormName
FROM tblWidget W
JOIN tblFormType FT ON (W.FormTypeID = FT.FormTypeID)
WHERE W.CreateTS >= DATEADD(YEAR, -1, @RunDate)
GROUP BY DATEPART(week, w.CreateTS), FT.FormName