代码实现自定义用户调查报表,显示上个月所有技术员的已发送调查数,被回答的调查数及平均满意度
以下sql语句适用于SQL server 2017:
SELECT ti.first_name "Technician",COUNT(srm.RESPONSEID) "NO of Survey sent", COUNT(case when responsetime is not null then 1 else null end) "No of Survey Answered" , avg(srm.result) "Satisfaction Level" FROM Survey_Response_Main srm left JOIN SurveyResponseRequestMapping srrm ON srm.RESPONSEID=srrm.RESPONSEID LEFT JOIN WorkOrder wo ON srrm.WORKORDERID=wo.WORKORDERID LEFT JOIN WorkOrderStates wos ON wo.WORKORDERID=wos.WORKORDERID LEFT JOIN SDUser AS td ON wos.OWNERID = td.USERID LEFT JOIN AaaUser AS ti ON td.USERID = ti.USER_ID LEFT JOIN Survey_Response_Comment srcmt ON srm.RESPONSEID=srcmt.RESPONSEID where wo.CREATEDTIME >=<from_lastmonth> and wo.CREATEDTIME <=<to_lastmonth> group by ti.first_name order by "Satisfaction Level" desc
所得报表样式: