select
c.preSales as '人员',
'月度完成金额(元)' as '统计项',
DATE_FORMAT(c.serviceStartAt, '%Y-%m') as '月份',
c.contractAmount as '金额'
from itsm_service_contract c
where c.preSales is not null
union all
select
c.preSales as '人员',
'续签金额(元)' as '统计项',
DATE_FORMAT(c.serviceStartAt, '%Y-%m') as '月份',
c.contractAmountOld as '金额'
from itsm_service_contract c
where c.preSales is not null
union all
select
c.preSales as '人员',
'扩签金额(元)' as '统计项',
DATE_FORMAT(c.serviceStartAt, '%Y-%m') as '月份',
c.contractAmountExt as '金额'
from itsm_service_contract c
where c.preSales is not null
union all
select
c.preSales as '人员',
'新签金额(元)' as '统计项',
DATE_FORMAT(c.serviceStartAt, '%Y-%m') as '月份',
c.contractAmountNew as '金额'
from itsm_service_contract c
where c.preSales is not null
union all
select
c.preSales as '人员',
'月度目标完成率' as '统计项',
DATE_FORMAT(c.serviceStartAt, '%Y-%m') as '月份',
CONCAT(ROUND(IF(kpi.amount is null or kpi.amount = 0,0,sum(c.contractAmountNew)/kpi.amount)*100,2),'%') as '金额'
from itsm_service_contract c
left join (
select
user,
month,
sum(amount) as amount
from itsm_report_user_kpi_target
group by user,month
) kpi on kpi.user = c.preSales
and DATE_FORMAT(kpi.month, '%Y-%m') =DATE_FORMAT(c.serviceStartAt, '%Y-%m')
where c.preSales is not null
group by c.preSales,DATE_FORMAT(c.serviceStartAt, '%Y-%m')
union all
select
c.preSales as '人员',
'存量目标完成率' as '统计项',
DATE_FORMAT(c.serviceStartAt, '%Y-%m') as '月份',
CONCAT(ROUND(IF(kpi.amount is null or kpi.amount = 0,0,sum(c.contractAmountNew)/kpi.amount)*100,2),'%') as '金额'
from itsm_service_contract c
left join itsm_report_user_kpi_target kpi on kpi.user = c.preSales
and DATE_FORMAT(kpi.month, '%Y-%m') =DATE_FORMAT(c.serviceStartAt, '%Y-%m')
and kpi.type = '存量'
where c.preSales is not null
group by c.preSales,DATE_FORMAT(c.serviceStartAt, '%Y-%m')
union all
select
c.preSales as '人员',
'新量目标完成率' as '统计项',
DATE_FORMAT(c.serviceStartAt, '%Y-%m') as '月份',
CONCAT(ROUND(IF(kpi.amount is null or kpi.amount = 0,0,sum(c.contractAmountNew)/kpi.amount)*100,2),'%') as '金额'
from itsm_service_contract c
left join itsm_report_user_kpi_target kpi on kpi.user = c.preSales
and DATE_FORMAT(kpi.month, '%Y-%m') =DATE_FORMAT(c.serviceStartAt, '%Y-%m')
and kpi.type = '新量'
group by c.preSales,DATE_FORMAT(c.serviceStartAt, '%Y-%m')
union all
select
c.preSales as '人员',
'应移交合约数量(个)' as '统计项',
DATE_FORMAT(c.serviceStartAt, '%Y-%m') as '月份',
count(1) as '金额'
from itsm_service_contract c
where c.preSales is not null
group by c.preSales,DATE_FORMAT(c.serviceStartAt, '%Y-%m')
union all
select
c.preSales as '人员',
'已移交合约数量(个)' as '统计项',
DATE_FORMAT(c.serviceStartAt, '%Y-%m') as '月份',
count(1) as '金额'
from itsm_service_contract c
where c.preSales is not null
and status = '已审核'
group by c.preSales,DATE_FORMAT(c.serviceStartAt, '%Y-%m')
union all
select
c.preSales as '人员',
'合约移交率' as '统计项',
DATE_FORMAT(c.serviceStartAt, '%Y-%m') as '月份',
CONCAT(ROUND((sum(if(status = '已审核',1,0))/count(1))*100,2),'%') as '金额'
from itsm_service_contract c
where c.preSales is not null
group by c.preSales,DATE_FORMAT(c.serviceStartAt, '%Y-%m') |