select
SUM(t1.Issue_Num) Issue_Num,
t1.Short_Name,
t1.Subsidiary,
dateadd(month, datediff(month, 0,t1.Apply_Time), 0) as Start_Date,
dateadd(month, datediff(month, 0, dateadd(month, 1, t1.Apply_Time)), -1) as End_Date,
cast("Year" as varchar)+'年'+cast("Month" as varchar)+'月报' as '报告期',
case when t2.Issue_NumT = 0 then 0 else (t1.Issue_Num - t2.Issue_NumT)/ t2.Issue_NumT *100 end as YOY_Number,
'同比' as YOY,
t1.SignY,
null Issue_Reson,
distinct t1.Responsibility_Judgment
from
(select
Complaint.Status,
Order_Num,
Apply_Time,
count(distinct ComplaintList.Responsibility_Judgment) as Issue_Num,
ComplaintList.Subsidiary,
ComplaintList.Responsibility_Judgment,
ComplaintList.SignY,
sub.Short_Name,
YEAR(Complaint.Apply_Time) Year,
MONTH(Complaint.Apply_Time) Month
from
[dbo].[IMP_MidDataCustomerComplaint] as Complaint
left join
[dbo].[IMP_MidDataComplaintList] as ComplaintList
on
Complaint.Serve_Order = ComplaintList.Serve_Order
left join
Mid_witsky.dbo.Base_Subsidiary as sub
on
sub.Code = ComplaintList.Subsidiary
where
--ComplaintList.Responsibility_Judgment = 'DT001'
--and Complaint.Status = 'OP002'
Complaint.Del_Flag = 0
and YEAR(Apply_Time) = 2025
and MONTH(Apply_Time) = 2
--and ComplaintList.Responsibility_Judgment = ''
and (Subsidiary is NULL
or Subsidiary = '')
group by
Complaint.Status,
Order_Num,
Apply_Time,
ComplaintList.Subsidiary,
ComplaintList.Responsibility_Judgment,
ComplaintList.SignY,
sub.Short_Name,
YEAR(Complaint.Apply_Time) ,
MONTH(Complaint.Apply_Time))t1
left join
(select
Complaint.Status as StatusT,
Order_Num as Order_NumT,
Apply_Time as Apply_TimeT,
count(distinct Complaint.Serve_Order) as Issue_NumT,
ComplaintList.Subsidiary as SubsidiaryT,
ComplaintList.Responsibility_Judgment as RJ,
ComplaintList.SignY as SignYT,
sub.Short_Name as NameT,
YEAR(Complaint.Apply_Time) YearT,
MONTH(Complaint.Apply_Time) MonthT
from
[dbo].[IMP_MidDataCustomerComplaint] as Complaint
left join
[dbo].[IMP_MidDataComplaintList] as ComplaintList
on
Complaint.Serve_Order = ComplaintList.Serve_Order
left join
Mid_witsky.dbo.Base_Subsidiary as sub
on
sub.Code = ComplaintList.Subsidiary
where
--ComplaintList.Responsibility_Judgment = 'DT001'
--and Complaint.Status = 'OP002'
Complaint.Del_Flag = 0
--and ComplaintList.Responsibility_Judgment = ''
and Subsidiary is NULL
or Subsidiary = ''
group by
Complaint.Status,
Order_Num,
Apply_Time,
ComplaintList.Subsidiary,
ComplaintList.Responsibility_Judgment,
ComplaintList.SignY,
sub.Short_Name,
YEAR(Complaint.Apply_Time) ,
MONTH(Complaint.Apply_Time))t2
on t1.year - 1 = t2.YearT
and t1.month = t2.MonthT
and t1.Subsidiary = t2.SubsidiaryT
where
t1.Month in('2')
and t1.SignY = 'CA002'
and t1.Year > (
case
when '3年' = '3年' then cast('2025' as INTEGER) -3
when '3年' = '5年' then cast('2025' as INTEGER) -5
when '3年' = '10年' then cast('2025' as INTEGER) -10
when '3年' = '15年' then cast('2025' as INTEGER) -15
else cast('2025' as INTEGER) -20
end
)
group by
t1.Short_Name,
t1.Subsidiary,
dateadd(month, datediff(month, 0,t1.Apply_Time), 0),
dateadd(month, datediff(month, 0, dateadd(month, 1, t1.Apply_Time)), -1) ,
cast("Year" as varchar)+'年'+cast("Month" as varchar)+'月报' ,
case when t2.Issue_NumT = 0 then 0 else (t1.Issue_Num - t2.Issue_NumT)/ t2.Issue_NumT *100 end ,
t1.SignY,
t1.Year,
t1.Month,
t1.Responsibility_Judgment
order by Year desc,Month desc 为什么会在添加distinct t1.Responsibility_Judgment后报错