我正在尝试使用以下标准显示摘要表:
未结工单数
紧急纠正维护工单的数量> 5天
日常纠正性维护工单的数量> 14天
常规PM的数量> 30天
生命安全PM的数量> 20天
其他工作单> 30天(不包括在2-5以上;不是常规纠正,紧急纠正或PM)
总计2-6(这是不在正常范围内的工作单数)
已打开的工作天数如果可能,已打开工作单;今天 - 最早的开放工单日期,#天数
过去30天内关闭的工单数
SELECT vWorkOrders.DateCreated AS 'Date',
SUM(CASE WHEN (DateDiff(d,vWorkOrders.DateCreated,GETDATE()) >5) AND TypeCode='CM' AND PriorityCode=’2’ THEN 1 ELSE 0 END) AS 'Urgent Corrective Maintenance > 5 Days',
SUM(CASE WHEN (DateDiff(d,vWorkOrders.DateCreated,GETDATE()) >14) AND TypeCode='CM' AND PriorityCode=’3’ THEN 1 ELSE 0 END) AS 'Routine Corrective Maintenance > 14 Days',
SUM(CASE WHEN (DateDiff(d,vWorkOrders.DateCreated,GETDATE()) >20) AND TypeCode='PM' AND PriorityCode=’7’ THEN 1 ELSE 0 END) AS 'Life Safety Preventive Maintenance > 20 Days'
SUM(CASE WHEN (DateDiff(d,vWorkOrders.DateCreated,GETDATE()) >30) AND TypeCode='PM' AND PriorityCode=’3’ AND PriorityCode=’2’ THEN 1 ELSE 0 END) AS 'Preventive Maintenance > 30 Days',
SUM(CASE WHEN (DateDiff(d,vWorkOrders.DateCreated,GETDATE()) >30) AND TypeCode<>'PM' AND TypeCode<>'CM' AND PriorityCode<>’7’ AND PriorityCode<>’3’ AND PriorityCode<>’2’ THEN 1 ELSE 0 END) AS 'Other > 30 Days',
COUNT(*) AS 'Total',
SUM(CASE WHEN StatusCode IN ('ACTIV','PENDG’) THEN 1 ELSE 0 END) AS 'Active Work Orders',
SUM(CASE WHEN (vWorkOrders.CompleteDate BETWEEN CAST(MONTH(GETDATE()) AS VARCHAR) + '/1/' + CAST(YEAR(GETDATE()) AS VARCHAR) AND DATEADD(SECOND, -1, DATEADD(MONTH, 1, CAST(MONTH(GETDATE()) AS VARCHAR) + '/1/' + CAST(YEAR(GETDATE()) AS VARCHAR)))) AND StatusCode=’CMPLT’ THEN 1 ELSE 0 END) AS 'of Work Orders closed in last 30 Days’,
SUM(CASE WHEN (DateDiff(d, GETDATE(), MIN(vWorkOrders.DateCreated)) THEN 1 ELSE 0 END) AS 'Days Open',
FROM vWorkOrders
WHERE vWorkOrders.IDSegment = 2 OR vWorkOrders.IDSegment = 5
AND (vWorkOrders.DateCreated BETWEEN '1/1/' + CAST(YEAR(GETDATE()) AS VARCHAR) AND '12/31/' + CAST(YEAR(GETDATE()) AS VARCHAR) + ' 23:59')
AND vWorkOrders.StatusCode IN ('ACTIV','PENDG')
GROUP BY vWorkOrders.DateCreated
ORDER BY vWorkOrders.DateCreated DESC
答案 0 :(得分:1)
你错过了
之后的逗号Life Safety Preventive Maintenance > 20 Days
这里你也有不同的报价类型:
('ACTIV','PENDG’)
......你在这里也有不同的引用:
'of Work Orders closed in last 30 Days’,
请...尝试使用onlu 1类型的报价