我正在尝试按某些人群对我的数据进行排序。我的数据看起来像:
Origional_Date ID FORM Total
2012-03-01 1855 3 1283
2012-03-01 2869 4 2306
2012-03-01 5555 4 6440
2012-03-01 5555 3 8373
2012-03-01 2527 3 8476
2012-03-01 922 3 823
2012-03-15 2907 4 1420
2012-03-15 5555 3 2892
2012-03-15 2914 4 5008
2012-03-15 2375 3 4594
到目前为止我的查询是:
DECLARE @StartDate smalldatetime, @EndDate smalldatetime, @Web_ID as smallint
SET @StartDate = '20120301'
SET @EndDate = '20120331'
SET @Web_ID = '5555'
SELECT DATEADD(WEEK, DATEDIFF(WEEK, 0, [Origional_Date]), -1) as [Origional_Date]
,[ID]
,[Form]
,SUM([Total]) as [Total]
FROM mytable
WHERE [Origional_Date] between @StartDate and @EndDate
AND [ID] = @Web_ID
GROUP BY DATEADD(WEEK, DATEDIFF(WEEK, 0, [Origional_Date]), -1), [ID], [Form]
ORDER BY [Origional_Date], [Form] ASC
我想要做的是显示我的数据,如:
Origional_Date ID FORM Total
2012-03-01 Web 3 8373
2012-03-01 Direct 3 10582
2012-03-01 Web 4 6440
2012-03-01 Direct 4 2306
2012-03-15 WEB 3 2892
2012-03-15 Direct 3 4594
2012-03-15 Direct 4 6428
Web 是 ID 5555,而 Direct 是其他任何东西。
我只是不确定如何使用“IF”语句来完成,或者是否需要在“group by”中完成
谢谢你!