0

我也在尝试按日期对它进行分组。我怎样才能做到这一点?我希望一组 0-30 岁,另一组 31-60 岁,最后一组 60 岁以上。我正在使用 SSRS 制作图表,并且需要水平轴为 0-31、31-60 和 60+。我尝试将“THEN P_NUMBER END) as Active_age”添加到 datediff 的末尾,但这不起作用。

SELECT COUNT(*) Assignment, Severity
FROM dashboard.dbo.SmTickets
WHERE Assignment IN('Crosby')
AND Severity IN(4)
AND datediff(day,Open_Time,GETDATE()) between 0 and 30 
group by Assignment, Severity
UNION 
SELECT COUNT(*) Assignment, Severity
FROM dashboard.dbo.SmTickets
WHERE Assignment IN('Crosby')
AND Severity IN(5)
AND datediff(day,Open_Time,GETDATE()) between 0 and 30 THEN P_NUMBER END) as Active_age
group by Assignment, Severity 
UNION 
SELECT COUNT(*) Assignment, Severity
FROM dashboard.dbo.SmTickets
WHERE Assignment IN('Crosby')
AND Severity IN(4)
AND datediff(day,Open_Time,GETDATE()) between 30.01 and 60
group by Assignment, Severity 
UNION
SELECT COUNT(*) Assignment, Severity
FROM dashboard.dbo.SmTickets
WHERE Assignment IN('Crosby')
AND Severity IN(5)
AND datediff(day,Open_Time,GETDATE()) between 30.01 and 60
group by Assignment, Severity 
UNION 
SELECT COUNT(*) Assignment, Severity
FROM dashboard.dbo.SmTickets
WHERE Assignment IN('Crosby')
AND Severity IN(4)
AND datediff(day,Open_Time,GETDATE()) > 60
group by Assignment, Severity 
UNION
SELECT COUNT(*) Assignment, Severity
FROM dashboard.dbo.SmTickets
WHERE Assignment IN('Crosby')
AND Severity IN(5)
AND datediff(day,Open_Time,GETDATE()) > 60
group by Assignment, Severity 
4

1 回答 1

1

尝试类似的东西

Select Assignment,Severity,[Days],Sum(NumberOfThingies) From
(
select Assignment,Severity,1 as NumberOfThingies, 
case when datediff(day,Open_Time,GETDATE) <= 30 Then '0 - 30'
case when datediff(day,Open_Time,GETDATE) <= 60 then '30 - 60'
else 'More than 60'
end as [Days]
FROM dashboard.dbo.SmTickets
Where Assignment in('Crosby') and Severity In (4,5)
) dummyname
Group By Assignment,Severity,[Days]
于 2013-06-14T14:18:35.380 回答