SELECT "wo"."WORKORDERID" AS "请求ID", "ti"."FIRST_NAME" AS "作业技术员" ,ques.ques1 AS "满意度问题一", ques.ques2 AS "满意度问题二", ques.ques3 AS "满意度问题三", ques.ques4 AS "满意度问题四",resp.Commenttext 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 ( select srrma.WORKORDERID,
stuff((select ''+(case srb.QUESID when 1 then srb.Value end) as "test1"
from Survey_Response_Answer srb left join SurveyResponseRequestMapping srrmb ON srrmb.responseid=srb.RESPONSEID
where srrmb.WORKORDERID=srrma.workorderid
for xml path('')),1,0,'')as "ques1",
stuff((select ''+(case srb.QUESID when 2 then srb.Value end) as "test2"
from Survey_Response_Answer srb left join SurveyResponseRequestMapping srrmb ON srrmb.responseid=srb.RESPONSEID
where srrmb.WORKORDERID=srrma.workorderid
for xml path('')),1,0,'')as "ques2",
stuff((select ''+(case srb.QUESID when 3 then srb.Value end) as "test3"
from Survey_Response_Answer srb left join SurveyResponseRequestMapping srrmb ON srrmb.responseid=srb.RESPONSEID
where srrmb.WORKORDERID=srrma.workorderid
for xml path('')),1,0,'')as "ques3",
stuff((select ''+(case srb.QUESID when 4 then srb.Value end) as "test4"
from Survey_Response_Answer srb left join SurveyResponseRequestMapping srrmb ON srrmb.responseid=srb.RESPONSEID
where srrmb.WORKORDERID=srrma.workorderid
for xml path('')),1,0,'')as "ques4"
from SurveyResponseRequestMapping srrma LEFT JOIN Survey_Response_Answer sra ON
srrma.responseid=sra.responseid LEFT JOIN Survey_Question sq ON
sra.quesid=sq.quesid
group by srrma.workorderid) ques ON wo.WORKORDERID= ques.WORKORDERID
LEFT JOIN (select workorderid, Commenttext from survey_response_comment src left join surveyresponserequestmapping srm on src.responseid = srm.responseid) resp ON wo.WORKORDERID = resp.WORKORDERID
WHERE ( ( ( "wo"."CREATEDTIME" >= 1666540800000 ) AND ( ( "wo"."CREATEDTIME" != 0 ) AND ( "wo"."CREATEDTIME" IS NOT NULL ) ) ) AND ( ( "wo"."CREATEDTIME" <= 1667145599999 ) AND ( ( ( "wo"."CREATEDTIME" != 0 ) AND ( "wo"."CREATEDTIME" IS NOT NULL ) ) AND ( "wo"."CREATEDTIME" != -1 ) ) ) ) AND wo.ISPARENT='1'
SELECT wo.WORKORDERID AS "请求ID", ti.FIRST_NAME AS "作业技术员" ,ques.ques1 AS "满意度问题一", ques.ques2 AS "满意度问题二", ques.ques3 AS "满意度问题三", resp.Commenttext 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 (select srrm.workorderid,
string_agg((case sq.quesid when '1' then answer end),null) as "ques1",
string_agg((case sq.quesid when '2' then answer end),null) as "ques2",
string_agg((case sq.quesid when '3' then answer end),null) as "ques3"
from SurveyResponseRequestMapping srrm LEFT JOIN Survey_Response_Answer sra ON srrm.responseid=sra.responseid LEFT JOIN Survey_Question sq ON sra.quesid=sq.quesid group by srrm.workorderid) ques ON wo.workorderid=ques.workorderid
LEFT JOIN (select workorderid, Commenttext from survey_response_comment src left join surveyresponserequestmapping srm on src.responseid = srm.responseid) resp ON wo.WORKORDERID = resp.WORKORDERID
WHERE ( ( ( wo.CREATEDTIME >= 1666454400000 ) AND ( ( wo.CREATEDTIME != 0 ) AND ( wo.CREATEDTIME IS NOT NULL ) ) ) AND ( ( wo.CREATEDTIME <= 1667059199999 ) AND ( ( ( wo.CREATEDTIME != 0 ) AND ( wo.CREATEDTIME IS NOT NULL ) ) AND ( wo.CREATEDTIME != -1 ) ) ) ) AND wo.ISPARENT='1'