Currently percentage seems to be calculating percentage on Total number of Calls and Percentage exceeding SLA not working properly at all,
Please Help
SELECT au.FIRST_NAME 'Technician',(SELECT COUNT(wo4.WORKORDERID) FROM Workorder_Threaded wot4 INNER JOIN workorder wo4 ON wo4.WORKORDERID=wot4.WORKORDERID LEFT JOIN WorkOrderStates wos4 ON wos4.WORKORDERID=wo4.WORKORDERID WHERE (wot4.THD_WOID=wot4.WORKORDERID) AND wo4.CREATEDTIME >= <from_thisweek> AND wo4.CREATEDTIME <= <to_thisweek> AND wos4.OWNERID=(wos0.OWNERID)) 'Total Number of calls',(SELECT COUNT(wo.WORKORDERID) FROM WorkOrder_Threaded wot INNER JOIN WorkOrder wo ON wot.WORKORDERID=wo.WORKORDERID LEFT JOIN WorkOrderStates wos ON wo.WORKORDERID=wos.WORKORDERID LEFT JOIN StatusDefinition std ON wos.STATUSID=std.STATUSID WHERE (( std.STATUSNAME = 'Closed') OR ( std.STATUSNAME = 'Resolved')) AND (wot.THD_WOID=wot.WORKORDERID) AND wo.COMPLETEDTIME >= <from_thisweek> AND wo.COMPLETEDTIME <= <to_thisweek> AND wos.OWNERID=(wos0.OWNERID))
'Total Closed/Resolved Calls',(SELECT COUNT(wo3.WORKORDERID) FROM WorkOrder_Threaded wot INNER JOIN WorkOrder wo3 ON wot.WORKORDERID=wo3.WORKORDERID LEFT JOIN WorkOrderStates wos ON wo3.WORKORDERID=wos.WORKORDERID LEFT JOIN StatusDefinition std ON wos.STATUSID=std.STATUSID WHERE (( std.STATUSNAME = 'Closed') OR ( std.STATUSNAME = 'Resolved')) AND wos.ISOVERDUE = '0' AND wo3.COMPLETEDTIME >= <from_thisweek> AND wo3.COMPLETEDTIME <= <to_thisweek> AND wot.THD_WOID=wot.WORKORDERID AND wos.OWNERID=(wos0.OWNERID))
'Total Closed/Resolved within SLA',(SELECT COUNT(wo3.WORKORDERID) FROM WorkOrder_Threaded wot INNER JOIN WorkOrder wo3 ON wot.WORKORDERID=wo3.WORKORDERID LEFT JOIN WorkOrderStates wos ON wo3.WORKORDERID=wos.WORKORDERID LEFT JOIN StatusDefinition std ON wos.STATUSID=std.STATUSID WHERE (( std.STATUSNAME = 'Closed') OR ( std.STATUSNAME = 'Resolved')) AND wos.ISOVERDUE = '1' AND wot.THD_WOID=wot.WORKORDERID AND wo3.COMPLETEDTIME >= <from_thisweek> AND wo3.COMPLETEDTIME <= <to_thisweek> AND wos.OWNERID=(wos0.OWNERID))
'Closed exceeding SLA',CASE WHEN (SELECT COUNT(wo.WORKORDERID) FROM WorkOrder_Threaded wot INNER JOIN WorkOrder wo ON wot.WORKORDERID=wo.WORKORDERID LEFT JOIN WorkOrderStates wos ON wo.WORKORDERID=wos.WORKORDERID LEFT JOIN StatusDefinition std ON wos.STATUSID=std.STATUSID WHERE (( std.STATUSNAME = 'Closed') OR ( std.STATUSNAME = 'Resolved')) AND (wot.THD_WOID=wot.WORKORDERID) AND wo.COMPLETEDTIME >= <from_thisweek> AND wo.COMPLETEDTIME <= <to_thisweek> AND wos.OWNERID=(wos0.OWNERID)) >0 THEN (SELECT count(wo.workorderid) FROM WorkOrder_Threaded wot INNER JOIN WorkOrder wo ON wot.WORKORDERID=wo.WORKORDERID LEFT JOIN WorkOrderStates wos ON wo.WORKORDERID=wos.WORKORDERID LEFT JOIN StatusDefinition std ON wos.STATUSID=std.STATUSID WHERE (( std.STATUSNAME = 'Closed') OR ( std.STATUSNAME = 'Resolved')) and wot.THD_WOID=wot.WORKORDERID and wo.CREATEDTIME >= <from_thisweek> AND wo.CREATEDTIME <= <to_thisweek> AND wos.OWNERID=(wos0.OWNERID)) * 100 / (select count(wo4.workorderid) from workorder_threaded wot4 INNER JOIN workorder wo4 on wo4.workorderid=wot4.workorderid left join workorderstates wos4 on wos4.workorderid=wo4.workorderid WHERE (wot4.THD_WOID=wot4.WORKORDERID) and wo4.CREATEDTIME >= <from_thisweek> AND wo4.CREATEDTIME <= <to_thisweek> and wos4.OWNERID=(wos0.OWNERID)) ELSE 0 END 'Percentage within SLA',CASE WHEN (SELECT COUNT(wo.WORKORDERID) FROM WorkOrder_Threaded wot INNER JOIN WorkOrder wo ON wot.WORKORDERID=wo.WORKORDERID LEFT JOIN WorkOrderStates wos ON wo.WORKORDERID=wos.WORKORDERID LEFT JOIN StatusDefinition std ON wos.STATUSID=std.STATUSID WHERE std.STATUSNAME = 'Closed' AND (wot.THD_WOID=wot.WORKORDERID) AND wo.COMPLETEDTIME >= <from_thisweek> AND wo.COMPLETEDTIME <= <to_thisweek> AND wos.OWNERID=(wos0.OWNERID)) >0 THEN (SELECT count(wo3.WORKORDERID) FROM WorkOrder_Threaded wot INNER JOIN WorkOrder wo3 ON wot.WORKORDERID=wo3.WORKORDERID LEFT JOIN WorkOrderStates wos ON wo3.WORKORDERID=wos.WORKORDERID LEFT JOIN StatusDefinition std ON wos.STATUSID=std.STATUSID WHERE (( std.STATUSNAME = 'Closed') OR ( std.STATUSNAME = 'Resolved')) AND ((wos.ISOVERDUE = '1') OR (wos.ISOVERDUE IS NULL)) and wot.THD_WOID=wot.WORKORDERID and wo3.CREATEDTIME >= <from_thisweek> AND wo3.CREATEDTIME <= <to_thisweek> and wos.OWNERID=(wos0.OWNERID)) * 100 / (select count(wo4.workorderid) from workorder_threaded wot4 INNER JOIN workorder wo4 on wo4.workorderid=wot4.workorderid left join workorderstates wos4 on wos4.workorderid=wo4.workorderid WHERE (wot4.THD_WOID=wot4.WORKORDERID) and wo4.CREATEDTIME >= <from_thisweek> AND wo4.CREATEDTIME <= <to_thisweek> and wos4.OWNERID=(wos0.OWNERID)) ELSE 0 END 'Percentage exceeding SLA' FROM WorkOrder_Threaded wot2 INNER JOIN WorkOrder wo2 ON wot2.WORKORDERID=wo2.WORKORDERID LEFT JOIN WorkOrderStates wos0 ON wos0.workorderid=wo2.workorderid LEFT JOIN AaaUser au ON au.user_id=wos0.ownerid WHERE (wot2.THD_WOID=wot2.WORKORDERID) AND wos0.OWNERID IS NOT NULL and wo2.CREATEDTIME >= <from_thisweek> AND wo2.CREATEDTIME <= <to_thisweek> GROUP BY au.first_name,wos0.OWNERID