ELECT Name,datee,SUM (val)
FROM @t
GROUP BY
GROUPING SETS((NAME ,datee), ())
select
final_medium_type, ACTIVITY_STATUS_CDE,
SUM(CASE WHEN DATEDIFF(second, Request_tms, Decision_tms) / 3600 = 0 THEN 1 ELSE 0 END ) as 'Less than 1 hrs',
SUM(CASE WHEN DATEDIFF(second, Request_tms, Decision_tms) / 3600 BETWEEN 1 and 4 THEN 1 ELSE 0 END ) as '1hr to 4hrs',
SUM(CASE WHEN DATEDIFF(second, Request_tms, Decision_tms) / 3600 BETWEEN 4 and 8 THEN 1 ELSE 0 END ) as '4hrs to 8hrs',
SUM(CASE WHEN DATEDIFF(second, Request_tms, Decision_tms) / 3600 BETWEEN 8 and 24 THEN 1 ELSE 0 END ) as 'Less than 1 day',
SUM(CASE WHEN DATEDIFF(second, Request_tms, Decision_tms) / 3600 BETWEEN 24 and 48 THEN 1 ELSE 0 END ) as '1 to 2 days',
SUM(CASE WHEN DATEDIFF(second, Request_tms, Decision_tms) / 3600 BETWEEN 48 and 72 THEN 1 ELSE 0 END ) as '2 days to 3 days',
SUM(CASE WHEN DATEDIFF(second, Request_tms, Decision_tms) / 3600 >= 72 THEN 1 ELSE 0 END ) as 'Greater than 3 days',
SUM(1) as 'Total'
from OpsDataB.dbo.specialty_eiw_pa_import
WHERE end_dte >= '01/01/2017'
AND ACTIVITY_STATUS_CDE = 'AP'
group by
GROUPING SETS((final_medium_type, ACTIVITY_STATUS_CDE), ())
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.