SELECT ad.org_name"Account",
SUM(CASE WHEN sdf.statusid='1' THEN 1 ELSE 0 END) "Count Of Open Request",
SUM(CASE WHEN sdf.statusid='3' THEN 1 ELSE 0 END) "Count Of Closed Request",
SUM(CASE(isoverdue) WHEN TRUE THEN 1 ELSE 0 END) "Count Of calls Exceeded SLA",
SUM(CASE(isoverdue) WHEN FALSE THEN 1 ELSE 1 END) "Count Of calls within SLA" ,
(SUM(CASE(isoverdue) WHEN TRUE THEN 1 ELSE 0 END)*100)/COUNT(wo.workorderid) "% Calls Exceeded SLA",
((COUNT(wo.workorderid) - SUM(CASE(isoverdue) WHEN TRUE THEN 1 ELSE 0 END))*100)/COUNT(wo.workorderid) "% Of Calls Within SLA" FROM workorder wo
LEFT JOIN workorderstates wos ON wo.workorderid = wos.workorderid
LEFT JOIN statusdefinition sdf ON wos.statusid=sdf.statusid
LEFT JOIN sitedefinition sd ON sd.siteid=wo.siteid
LEFT JOIN accountsitemapping asm ON asm.siteid=sd.siteid
LEFT JOIN accountdefinition ad ON ad.org_id=asm.accountid
WHERE wo.CREATEDTIME >= <from_lastmonth>
AND wo.CREATEDTIME <= <to_lastmonth> GROUP BY ad.org_name