1

我的查询中有以下 group by 子句,它使用 case 语句,但我也想向 group by 添加另一列:

        group by case @dateType

WHEN 'Daily' then i.overridedate
WHEN 'Weekly' then dateadd(day,-1*datepart(weekday,i.overridedate)+1,i.overridedate) 
WHEN 'Monthly' THEN DATEADD(day, -1*DATEpart(day,i.overridedate)+1, i.overridedate) 
WHEN 'Quarterly' THEN dateadd(mm,-3,DATEADD(qq, DATEDIFF(qq,0,i.overridedate )+1, 0)) END

如何将另一列添加到该组?

4

1 回答 1

3
group by case @dateType
WHEN 'Daily' then i.overridedate
WHEN 'Weekly' then dateadd(day,-1*datepart(weekday,i.overridedate)+1,i.overridedate) 
WHEN 'Monthly' THEN DATEADD(day, -1*DATEpart(day,i.overridedate)+1, i.overridedate) 
WHEN 'Quarterly' THEN dateadd(mm,-3,DATEADD(qq, DATEDIFF(qq,0,i.overridedate )+1, 0)) END
--Edited
,
col1,
col2,
etc..,
coln
于 2013-07-09T09:35:40.853 回答