开发者

How To: Count widgets sold every 7 days for a period of a year

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.C开发者_Python百科reateTS, 101)AS  SMALLDATETIME), FT.FormName

The current Code aggregates the amount of widgets sold per day and goes back year - 1 day. I need to find out how many are sold per 7 days.

Any help would be awesome.


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜