在下面的代码中,我需要使用 Open_time 和当前时间进行计算,而不是活动年龄。
换句话说,如果当前时间减去 open_time 介于 0 和 30、31 和 60 或超过 60 之间,我需要这样做。
SELECT COUNT(CASE WHEN Assignment = 'Crosby' AND Severity = 4 AND CloseTime-OpenTime = 0-30 THEN P_NUMBER END) as crosby_sev4_030,
COUNT(CASE WHEN Assignment = 'Crosby' AND Severity = 5 AND Active_Age='0-30' THEN P_NUMBER END) as crosby_sev5_030,
COUNT(CASE WHEN Assignment = 'Crosby' AND Severity = 4 AND Active_Age='31-60' THEN P_NUMBER END) as crosby_sev4_3160,
COUNT(CASE WHEN Assignment = 'Crosby' AND Severity = 5 AND Active_Age='31-60' THEN P_NUMBER END) as crosby_sev5_3160,
COUNT(CASE WHEN Assignment = 'Crosby' AND Severity = 4 AND Active_Age='60+' THEN P_NUMBER END) as crosby_sev4_60,
COUNT(CASE WHEN Assignment = 'Crosby' AND Severity = 5 AND Active_Age='60+' THEN P_NUMBER END) as crosby_sev5_60
FROM dashboard.dbo.SmThings
WHERE Assignment IN('Crosby')
AND Severity IN(4,5)