SELECT
case when "ti"."FIRST_NAME" is not null then "ti"."FIRST_NAME" else '合计' end "工程师名",
count ("wo"."WORKORDERID") AS "工单受理量",
cast ( cast (100.0*sum(case when "wos"."IS_FR_OVERDUE"= 0 then 1 else 0 end)/count("wos"."IS_FR_OVERDUE") as decimal(18,2)) as varchar(6)) AS "工单按时响应率(%)",
cast ( cast (100.0*sum(case when "wos"."ISOVERDUE"= 0 then 1 else 0 end)/count("wos"."ISOVERDUE") as decimal(18,2)) as varchar(6)) AS "工单按时解决率(%)",
cast ( cast (100.0*sum(case when "wos"."REOPENED"= 1 then 1 else 0 end)/count("wos"."REOPENED") as decimal(18,2)) as varchar(6)) AS "二次开单率(%)",
cast ( avg (satis.satis)as decimal(18,2)) as "满意度(%)"
FROM "WorkOrder" "wo"
LEFT JOIN "WorkOrderStates" "wos" ON "wo"."WORKORDERID"="wos"."WORKORDERID"
LEFT JOIN "SDUser" "td" ON "wos"."OWNERID"="td"."USERID"
LEFT JOIN "AaaUser" "ti" ON "td"."USERID"="ti"."USER_ID"
LEFT JOIN "WorkOrder_Fields" "wof" ON "wo"."WORKORDERID"="wof"."WORKORDERID"
LEFT JOIN
(select wos.OWNERID, AVG(cast(ANSWER as decimal(18,2))) as "satis"
from "WorkOrder" "wo"
LEFT JOIN "WorkOrderStates" "wos" ON "wo"."WORKORDERID"="wos"."WORKORDERID"
LEFT JOIN SurveyResponseRequestMapping srrm ON wo.WORKORDERID=srrm.WORKORDERID
LEFT JOIN Survey_Response_Answer sra ON srrm.responseid=sra.responseid group by wos.OWNERID) satis ON wos.OWNERID=satis.OWNERID
group by "ti"."FIRST_NAME"
with rollup