我有一个工作订单表和客户满意度表。 我需要从工作订单中计算出不同的位置,并且我需要从客户满意度中计算出匹配的位置。常见的列是wo_number
select CONVERT(VARCHAR(7), DATEADD(MONTH, DATEDIFF(MONTH, 0, WO.wo_completionDate), 0), 111) AS [Period Date],
REPLACE(RIGHT(CONVERT(VARCHAR(11), DATEADD(MONTH, DATEDIFF(MONTH, 0, WO.wo_completionDate), 0), 106), 8), ' ', '-') AS Period,
count (distinct WO.fu_unitID),
count (distinct SR.fu_unitID)
from v_surveyResultRpt as SR
INNER JOIN v_workorder AS WO on SR.wo_number = WO.wo_number
where WO.wo_isClosed = '1' and WO.wo_charge = '1' and WO.rc_code = 'CD-HM'
and
DATEDIFF(MONTH,WO.wo_completionDate,getdate()) < 6
group by DATEADD(MONTH, DATEDIFF(MONTH, 0, WO.wo_completionDate), 0)
order by CONVERT(VARCHAR(7), DATEADD(MONTH, DATEDIFF(MONTH, 0, WO.wo_completionDate), 0), 111)
预期结果 YY月,来自客户满意度调查的Total_location,来自工作订单的总位置。 最终,它将使我从总工单中得到多少客户响应。
答案 0 :(得分:0)
如果有帮助,请使用下面的示例代码。
select CAST(MONTH(WO.wo_completionDate) AS VARCHAR(2)) +'-'+ CAST(YEAR(WO.wo_completionDate) AS VARCHAR(4)),
count (distinct WO.fu_unitID),
count (distinct SR.fu_unitID)
from v_surveyResultRpt as SR
INNER JOIN v_workorder AS WO on SR.wo_number = WO.wo_number
where WO.wo_isClosed = '1' and WO.wo_charge = '1' and WO.rc_code = 'CD-HM'
and DATEDIFF(MONTH,WO.wo_completionDate,getdate()) < 6
group by MONTH(WO.wo_completionDate), YEAR(WO.wo_completionDate)
order by YEAR(WO.wo_completionDate), MONTH(WO.wo_completionDate)