0

これも日付ごとにグループ化しようとしています。どうやってやるの?あるグループを 0 ~ 30、別のグループを 31 ~ 60、最後のグループを 60+ にします。SSRS でグラフを作成しており、横軸を 0-31、31-60、60+ にする必要があります。datediff の最後に "THEN P_NUMBER END) as Active_age" を追加しようとしましたが、うまくいきません。

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 に答える