Hi,
Please try the below query.
SELECT sdo.NAME "Site",
count(wo.WORKORDERID) "Total",
count(case when wos.ISOVERDUE='1' then 1 else null end) "Sla violated",
count(case when wos.ISOVERDUE='0' then 1 else null end) "Sla not violated",
case when count(wo.workorderid) > 0 then count(case when (wos.ISOVERDUE='1') THEN 1 ELSE NULL END) *100 / count(wo.workorderid) else null end "% Violated",
case when count(wo.workorderid) > 0 then count(case when (wos.ISOVERDUE='0') THEN 1 ELSE NULL END) *100 / count(wo.workorderid) else null end "% not Violated" FROM WorkOrder wo
LEFT JOIN SiteDefinition siteDef ON wo.SITEID=siteDef.SITEID
LEFT JOIN SDOrganization sdo ON siteDef.SITEID=sdo.ORG_ID
LEFT JOIN WorkOrderStates wos ON wo.WORKORDERID=wos.WORKORDERID LEFT JOIN WorkOrder_Queue woq ON wo.WORKORDERID=woq.WORKORDERID LEFT JOIN QueueDefinition qd ON woq.QUEUEID=qd.QUEUEID
Left join statusdefinition std on wos.statusid=std.statusid where qd.QUEUENAME like '%service%' and wo.CREATEDTIME >= <from_lastmonth> AND wo.CREATEDTIME <= <to_lastmonth> group by sdo.NAME
order by 1
Please try the below query.
SELECT sdo.NAME "Site",
count(wo.WORKORDERID) "Total",
count(case when wos.ISOVERDUE='1' then 1 else null end) "Sla violated",
count(case when wos.ISOVERDUE='0' then 1 else null end) "Sla not violated",
case when count(wo.workorderid) > 0 then count(case when (wos.ISOVERDUE='1') THEN 1 ELSE NULL END) *100 / count(wo.workorderid) else null end "% Violated",
case when count(wo.workorderid) > 0 then count(case when (wos.ISOVERDUE='0') THEN 1 ELSE NULL END) *100 / count(wo.workorderid) else null end "% not Violated" FROM WorkOrder wo
LEFT JOIN SiteDefinition siteDef ON wo.SITEID=siteDef.SITEID
LEFT JOIN SDOrganization sdo ON siteDef.SITEID=sdo.ORG_ID
LEFT JOIN WorkOrderStates wos ON wo.WORKORDERID=wos.WORKORDERID LEFT JOIN WorkOrder_Queue woq ON wo.WORKORDERID=woq.WORKORDERID LEFT JOIN QueueDefinition qd ON woq.QUEUEID=qd.QUEUEID
Left join statusdefinition std on wos.statusid=std.statusid where qd.QUEUENAME like '%service%' and wo.CREATEDTIME >= <from_lastmonth> AND wo.CREATEDTIME <= <to_lastmonth> group by sdo.NAME
order by 1