Commit ecc5d480 by 章家宝

config:九月大版本dml

1 parent ed8b9f65
### 章家宝 -----------------start--------------------
UPDATE report_export_query_sql
SET querysql = 'select
IFNULL(t0.员工手机号,t0.员工id) as 员工id ,t0.员工姓名,t1.员工手机号,t0.4s店商户号,t0.门店,主服务商id,(case when 主服务商名称=''深圳嘀加'' then ''直营'' else 主服务商名称 end) as 服务商,t0.业务类型,t0.scene_type,
订单数 ,
ifnull(总触客,0) 到店量人,
ifnull(是否派发平板,''否'')是否派发平板,
ifnull(t7.派发日期, ''--'') as 派发日期,
ifnull(接待天数,0)平板出勤,
DATEDIFF(
(case when date_format(''endtimexxxxxx'',''%Y-%m'')=date_format(date_sub(''endtimexxxxxx'',interval 1 week ),''%Y-%m'') then date_sub(''endtimexxxxxx'',interval 1 day ) else date_sub(date_format(''endtimexxxxxx'',''%Y-%m-01''),interval 1 day )end)
,(case when date_format(''endtimexxxxxx'',''%Y-%m'')=date_format(date_sub(''endtimexxxxxx'',interval 1 week ),''%Y-%m'') then date_format(''endtimexxxxxx'',''%Y-%m-01'') else date_sub(date_format(''endtimexxxxxx'',''%Y-%m-01''),interval 1 month )end)
)+2 从1号到上周日的实际天数,
DATEDIFF(
(case when date_format(''endtimexxxxxx'',''%Y-%m'')=date_format(date_sub(''endtimexxxxxx'',interval 1 week ),''%Y-%m'') then date_sub(''endtimexxxxxx'',interval 1 day ) else date_sub(date_format(''endtimexxxxxx'',''%Y-%m-01''),interval 1 day )end)
,(case when date_format(''endtimexxxxxx'',''%Y-%m'')=date_format(date_sub(''endtimexxxxxx'',interval 1 week ),''%Y-%m'') then date_format(''endtimexxxxxx'',''%Y-%m-01'') else date_sub(date_format(''endtimexxxxxx'',''%Y-%m-01''),interval 1 month )end)
)+2 -4 - ifnull(接待天数,0) as 平板缺勤,
ifnull(t5.接待次数,0) 预计接待批次数,
ifnull(t6.接待次数,0) 真实接待数量,
ifnull(总触客,0)- ifnull(t5.接待次数,0) as 录音缺失,
ifnull(t8.report_count, 0) as report_count,
ifnull(t8.approved_count, 0) as approved_count,
now() created_date
from (
SELECT
iam.custodian_phone AS 员工id,
'''' AS 4s店商户号,
'''' AS 业务类型,
'''' AS scene_type,
iam.custodian AS 员工姓名,
'''' AS 门店,
iam.custodian_phone AS 员工手机号
FROM inspection_asset_management iam
WHERE iam.deleted_flag = ''N''
AND NOT EXISTS (
SELECT 1
FROM dj_car_life_staff_info dclsi
WHERE dclsi.deleted_flag = ''N''
AND dclsi.phone_number = iam.custodian_phone
AND EXISTS (
SELECT 1
FROM dj_car_life_goods_order a
LEFT JOIN dj_car_life_pay_order b ON a.order_code = b.order_code
AND b.deleted_flag = ''N''
AND b.order_code IS NOT NULL
WHERE a.seller_user_id = dclsi.staff_uuid
AND a.deleted_flag = ''N''
AND a.status IN (2, 4, 6)
AND a.upgrade_flag IN (''Y'', ''N'')
AND a.seller_user_id IS NOT NULL
AND a.scene_type IN (0, 1)
AND DATE_FORMAT(IFNULL(b.success_date, a.order_time), ''%Y-%m-%d'')
BETWEEN DATE_SUB(DATE_FORMAT(''starttimexxxxxx'', ''%Y-%m-%d''), INTERVAL 1 MONTH) AND ''endtimexxxxxx''
)
)
union
select 员工id,4s店商户号,业务类型, scene_type,员工姓名,4s店商户名称 as 门店,员工手机号
from (
select ifnull(员工手机号,seller_user_id) ''员工id'',ifnull(员工姓名,seller_name) ''员工姓名'',dclgo.scene_type,merchant_id ''4s店商户号'' ,merchant_name ''4s店商户名称'',员工手机号,
(case when dclgo.scene_type=1 then ''精品升级'' when dclgo.scene_type=0 then ''会员权益/升级'' end) 业务类型
from(
select ifnull(b.success_date,a.order_time) order_time ,a.merchant_id, a.merchant_name, a.seller_user_id,a.scene_type,a.seller_name,a.status, a.deleted_flag, a.upgrade_flag
from dj_car_life_goods_order a
left join (select * from dj_car_life_pay_order where deleted_flag = ''N'' and order_code is not null) b on a.order_code=b.order_code
) dclgo
left join (
select staff_uuid 员工uuid,staff_name 员工姓名 ,phone_number 员工手机号 from dj_car_life_staff_info where deleted_flag = ''N''
)dclsi on dclgo.seller_user_id=dclsi.员工uuid
where dclgo.deleted_flag=''N''
and dclgo.status in (2, 4, 6)
and dclgo.upgrade_flag in (''Y'',''N'')
and seller_user_id is not null
and scene_type in (0,1)
and DATE_FORMAT(dclgo.order_time,''%Y-%m-%d'') between date_sub(date_format(''starttimexxxxxx'',''%Y-%m-%d''),INTERVAL 1 month)and ''endtimexxxxxx''
)t group by 员工id,4s店商户号,业务类型
)t0
left join (
select 员工id,4s店商户号,业务类型, scene_type,员工姓名,4s店商户名称 as 门店,
count(distinct (case when upgrade_flag=''Y'' then order_code else null end))订单数
from (
select ifnull(员工手机号,seller_user_id) ''员工id'',seller_name ''员工姓名'', dclgo.scene_type,merchant_id ''4s店商户号'' ,merchant_name ''4s店商户名称'',upgrade_flag,
dclgo.order_code,dclgoc.customer_phone,
(case when dclgo.scene_type=1 then ''精品升级'' when dclgo.scene_type=0 then ''会员权益/升级'' else null end) 业务类型
from(
select ifnull(DATE_FORMAT(b.success_date,''%Y-%m-%d''),DATE_FORMAT(a.order_time,''%Y-%m-%d'')) order_time ,a.merchant_id, a.merchant_name,a.order_code,
a.seller_user_id,a.scene_type,a.business_type,a.seller_name,a.seller_merchant_id,a.seller_merchant_name, a.status, a.deleted_flag, a.upgrade_flag,a.total_price
from dj_car_life_goods_order a
left join (select * from dj_car_life_pay_order where deleted_flag = ''N'' and order_code is not null) b on a.order_code=b.order_code
) dclgo
left join dj_car_life_goods_order_customer dclgoc on dclgo.order_code = dclgoc.order_code and dclgoc.deleted_flag = ''N''
left join (
select staff_uuid 员工uuid,staff_name 员工姓名 ,phone_number 员工手机号 from dj_car_life_staff_info where deleted_flag = ''N''
)dclsi on dclgo.seller_user_id=dclsi.员工uuid
where dclgo.deleted_flag=''N''
and dclgo.status in (2, 4, 6)
and dclgo.upgrade_flag in (''Y'',''N'')
and seller_user_id is not null
and scene_type in (0,1)
and order_time between date_format(''starttimexxxxxx'',''%Y-%m-%d'') and ''endtimexxxxxx''
)t group by 员工id,4s店商户号,业务类型
)t on t0.4s店商户号=t.4s店商户号 and t0.员工id=t.员工id and t0.业务类型=t.业务类型
left join (
select 员工uuid,员工姓名,员工手机号,是否派发平板,scene,主服务商id,主服务商名称,4s店商户号,4s店商户名称 , 园区店商户号 , 园区店商户名称 from (
select ifnull(员工手机号,员工uuid)员工uuid,员工姓名,员工手机号,是否派发平板,scene,主服务商id,主服务商名称,4s店商户号,4s店商户名称 , 园区店商户号 , 园区店商户名称
from (
select main_merchant_id ''4s店商户号'', main_merchant_name ''4s店商户名称'', sub_merchant_id ''园区店商户号'', sub_merchant_name ''园区店商户名称'',scene
from dj_car_life_scene_merchant_ref where deleted_flag = ''N''and scene in(0,1)and sub_merchant_type in (6,8)
)a inner join(
select merchant_id,partner_merchant_id 主服务商id,partner_merchant_name 主服务商名称 from dj_car_life_yqmerchant_config where deleted_flag = ''N''
)b on a.园区店商户号=b.merchant_id
inner join (
select staff_uuid 员工uuid,staff_name 员工姓名 ,phone_number 员工手机号,merchant_id 所属商户号,merchant_name 所属商户名称,
(case when phone_number in (select custodian_phone from inspection_asset_management ) then ''是''else ''否''end)是否派发平板
from dj_car_life_staff_info where deleted_flag = ''N''
)c on a.园区店商户号=c.所属商户号
)t group by 主服务商id,scene,员工uuid,4s店商户号
having 主服务商id is not null
)t1 on t0.员工id=t1.员工uuid and t0.4s店商户号=t1.4s店商户号 and t0.scene_type=t1.scene
-- 到店量数据来源: dj_car_life_staff_daily_report_huawei
left join(
select staff_uuid, 4s店店商户号, scene_type,
ifnull(sum(ifnull(equity_to_shop_count,0) + ifnull(after_sale_equity_to_shop_count,0)), 0) 总触客
from (
select ifnull(员工手机号,t.staff_uuid) staff_uuid, merchant_id as 4s店店商户号, t.scene_type,
equity_to_shop_count, after_sale_equity_to_shop_count, deleted_flag, report_date
from dj_car_life_staff_daily_report_huawei t
left join (
select staff_uuid 员工uuid, staff_name 员工姓名, phone_number 员工手机号 from dj_car_life_staff_info where deleted_flag = ''N''
) dclsi on t.staff_uuid = dclsi.员工uuid
) t
where deleted_flag = ''N''
and DATE_FORMAT(report_date, ''%Y-%m-%d'') between date_format(''starttimexxxxxx'', ''%Y-%m-%d'') and ''endtimexxxxxx''
group by 4s店店商户号, staff_uuid, scene_type
) t2 on t0.4s店商户号 = t2.4s店店商户号 and t0.员工id = t2.staff_uuid and t0.scene_type = t2.scene_type
left join (
select staff_uuid ,
count(distinct date_format (reception_start_time,''%Y-%m-%d'')) as 接待天数
from (
select ifnull(员工手机号,rcf.staff_uuid)staff_uuid,reception_start_time
from reception_customer_info rcf
left join (
select staff_uuid 员工uuid,staff_name 员工姓名 ,phone_number 员工手机号 from dj_car_life_staff_info where deleted_flag = ''N''
)dclsi on rcf.staff_uuid=dclsi.员工uuid
LEFT JOIN inspection_badge_recordings t2 ON rcf.id = t2.reception_id where t2.recording_start_time is not null
)t
where date_format (reception_start_time,''%Y-%m-%d'')between date_format(''starttimexxxxxx'',''%Y-%m-%d'') and ''endtimexxxxxx''
group by staff_uuid
)t4 on t0.员工id=t4.staff_uuid
left join (
select staff_uuid ,bussiness_type, merchant_id,
count(1)接待次数
from (
select ifnull(员工手机号,rcf.staff_uuid)staff_uuid,(case when bussiness_type=2 then 1 when bussiness_type=1 then 0 end )bussiness_type, merchant_id,reception_start_time
from reception_customer_info rcf
left join (
select staff_uuid 员工uuid,staff_name 员工姓名 ,phone_number 员工手机号 from dj_car_life_staff_info where deleted_flag = ''N''
)dclsi on rcf.staff_uuid=dclsi.员工uuid
LEFT JOIN inspection_badge_recordings t2 ON rcf.id = t2.reception_id where t2.recording_start_time is not null
)t
where date_format (reception_start_time,''%Y-%m-%d'')between date_format(''starttimexxxxxx'',''%Y-%m-%d'') and ''endtimexxxxxx''
group by staff_uuid ,bussiness_type,merchant_id
)t5 on t0.4s店商户号=t5.merchant_id and t0.员工id=t5.staff_uuid and t0.scene_type=t5.bussiness_type
left join (
SELECT
t1.staff_uuid,(case when t1.bussiness_type=2 then 1 when t1.bussiness_type=1 then 0 end )bussiness_type,t1.merchant_id,
count(1) as ''接待次数'', AVG(t3.score) as 质检平均分
FROM (select ifnull(员工手机号,t1.staff_uuid)staff_uuid,bussiness_type,id,merchant_id,reception_start_time from reception_customer_info t1
left join ( select staff_uuid 员工uuid,staff_name 员工姓名 ,phone_number 员工手机号 from dj_car_life_staff_info where deleted_flag = ''N''
)dclsi on t1.staff_uuid=dclsi.员工uuid
) t1
LEFT JOIN inspection_badge_recordings t2 ON t1.id = t2.reception_id
LEFT JOIN inspection_conversation_batch t3 ON t2.id = t3.record_id
where t2.che_result_flag =2 and t3.score>20
and date_format (reception_start_time,''%Y-%m-%d'')between date_format(''starttimexxxxxx'',''%Y-%m-%d'') and ''endtimexxxxxx''
GROUP BY t1.staff_uuid, t1.bussiness_type, t1.merchant_id
)t6 on t0.4s店商户号=t6.merchant_id and t0.员工id=t6.staff_uuid and t0.scene_type=t6.bussiness_type
-- 派发日期关联查询
left join (
select custodian_phone, DATE_FORMAT(MAX(dis_date), ''%Y-%m-%d'') as 派发日期
from inspection_asset_management
where deleted_flag = ''N''
group by custodian_phone
) t7 on t1.员工手机号 = t7.custodian_phone
-- 【新增】系统报备数量关联查询
left join (
select staff_phone,
COUNT(*) as report_count,
SUM(CASE WHEN audit_status = 1 THEN 1 ELSE 0 END) as approved_count
from reception_missing_report
where deleted_flag = ''N''
and report_date between date_format(''starttimexxxxxx'', ''%Y-%m-%d'') and ''endtimexxxxxx''
group by staff_phone
) t8 on t1.员工手机号 = t8.staff_phone
having 门店 not in (''杰西集团的门店2'',''杰西集团的门店'',''内部测试4S店'')
',
update_date = now(),
ver_desc = '9月版本: 到店量按scene_type区分业务'
WHERE sqlname = 'querySellerUserUsedipadAnalysis01'
AND deleted_flag = 'N';
UPDATE report_export_query_sql
SET querysql = 'select 4s店商户号,员工id,场景 scene_type,业务类型,sum(日报有误天)日报有误天数 from(
select
ifnull(t.员工手机号,t.员工id)as 员工id , t.场景, t.4s店商户号, t.业务类型,员工手机号,订单数 ,ifnull(总触客,0) 到店量人,ifnull(t6.接待次数,0) 真实接待数量,
(case when 总触客 is null then 1 else (case when 总触客>ifnull(t6.接待次数,0) or ifnull(订单数,0)>总触客 then 1 else 0 end)end)日报有误天
from (
SELECT ifnull(员工手机号,员工id)员工id,统计时间,4s店商户号,场景,业务类型,员工手机号 FROM (
SELECT distinct t1.staff_uuid 员工id, DATE_FORMAT(t1.reception_start_time, ''%Y-%m-%d'') AS 统计时间,t1.merchant_id 4s店商户号,
(case when t1.bussiness_type=2 then 1 when t1.bussiness_type=1 then 0 end )场景, (case when t1.bussiness_type=2 then ''精品升级'' when t1.bussiness_type=1 then ''会员权益/升级'' else null end) 业务类型
FROM reception_customer_info t1
LEFT JOIN inspection_badge_recordings t2 ON t1.id = t2.reception_id
LEFT JOIN inspection_conversation_batch t3 ON t2.id = t3.record_id
where t2.che_result_flag =2 and t3.score>20
and date_format (reception_start_time,''%Y-%m-%d'')between date_format(''starttimexxxxxx'',''%Y-%m-%d'') and ''endtimexxxxxx''
GROUP BY t1.staff_uuid, t1.bussiness_type, t1.merchant_id,date_format (reception_start_time,''%Y-%m-%d'')
union
select distinct 员工id,统计时间,4s店商户号,scene_type 场景,业务类型 from (
select seller_user_id''员工id'',seller_name ''员工姓名'',dclgo.scene_type,merchant_id ''4s店商户号'' ,merchant_name ''4s店商户名称'',
(case when dclgo.scene_type=1 then ''精品升级'' when dclgo.scene_type=0 then ''会员权益/升级'' end) 业务类型,
DATE_FORMAT(dclgo.order_time,''%Y-%m-%d'')统计时间
from(
select ifnull(b.success_date,a.order_time) order_time ,a.merchant_id, a.merchant_name, a.seller_user_id,a.scene_type,a.seller_name,a.status, a.deleted_flag, a.upgrade_flag
from dj_car_life_goods_order a
left join (select * from dj_car_life_pay_order where deleted_flag = ''N'' and order_code is not null) b on a.order_code=b.order_code
) dclgo
where dclgo.deleted_flag=''N''and dclgo.status in (2, 4, 6)and dclgo.upgrade_flag in (''Y'',''N'')and seller_user_id is not null and scene_type in (0,1)
and DATE_FORMAT(dclgo.order_time,''%Y-%m-%d'') between date_format(''starttimexxxxxx'',''%Y-%m-%d'')and ''endtimexxxxxx''
)t group by 员工id,统计时间,4s店商户号,业务类型
union
select distinct staff_uuid 员工id,DATE_FORMAT(report_date,''%Y-%m-%d'')统计时间,merchant_id 4s店商户号,scene_type 场景, (case when scene_type=1 then ''精品升级'' when scene_type=0 then ''会员权益/升级'' else null end) 业务类型
from dj_car_life_staff_daily_report_huawei
where deleted_flag = ''N''
and DATE_FORMAT(report_date,''%Y-%m-%d'')between date_format(''starttimexxxxxx'',''%Y-%m-%d'') and ''endtimexxxxxx''
)tt
left join (
select staff_uuid 员工uuid,staff_name 员工姓名 ,phone_number 员工手机号 from dj_car_life_staff_info where deleted_flag = ''N''
)dclsi on tt.员工id=dclsi.员工uuid
)t left join (
select 员工id,4s店商户号,业务类型, scene_type,order_time,
员工姓名,4s店商户名称 as 门店,
sum(total_price) 产值,
count(distinct (case when upgrade_flag=''Y'' then order_code else null end))订单数
from (
select order_time,ifnull(员工手机号,seller_user_id)''员工id'',seller_name ''员工姓名'',dclgo.scene_type,merchant_id ''4s店商户号'',merchant_name ''4s店商户名称'',upgrade_flag,dclgo.order_code,dclgoc.customer_phone,total_price,
(case when dclgo.scene_type=1 then ''精品升级'' when dclgo.scene_type=0 then ''会员权益/升级'' else null end) 业务类型
from(
select ifnull(DATE_FORMAT(b.success_date,''%Y-%m-%d''),DATE_FORMAT(a.order_time,''%Y-%m-%d'')) order_time ,a.merchant_id, a.merchant_name,a.order_code,
a.seller_user_id,a.scene_type,a.business_type,a.seller_name,a.seller_merchant_id,a.seller_merchant_name,
a.status, a.deleted_flag, a.upgrade_flag,a.total_price
from dj_car_life_goods_order a
left join (
select * from dj_car_life_pay_order where deleted_flag = ''N'' and order_code is not null
) b on a.order_code=b.order_code
) dclgo
left join dj_car_life_goods_order_customer dclgoc on dclgo.order_code = dclgoc.order_code and dclgoc.deleted_flag = ''N''
left join ( select staff_uuid 员工uuid,staff_name 员工姓名 ,phone_number 员工手机号 from dj_car_life_staff_info where deleted_flag = ''N''
)dclsi on dclgo.seller_user_id=dclsi.员工uuid
where dclgo.deleted_flag=''N''
and dclgo.status in (2, 4, 6)
and dclgo.upgrade_flag in (''Y'',''N'')
and seller_user_id is not null
and scene_type in (0,1)
and order_time between date_format(''starttimexxxxxx'',''%Y-%m-%d'') and ''endtimexxxxxx''
)t group by 员工id,4s店商户号,业务类型,order_time
)t0 on t.4s店商户号=t0.4s店商户号 and t.员工id=t0.员工id and t.场景=t0.scene_type and t.统计时间=t0.order_time
left join(
select staff_uuid, 4s店店商户号, scene_type, report_date,
ifnull(sum(ifnull(equity_to_shop_count,0) + ifnull(after_sale_equity_to_shop_count,0)), 0) 总触客
from (
select ifnull(员工手机号,t.staff_uuid) staff_uuid, merchant_id as 4s店店商户号, t.scene_type,
DATE_FORMAT(report_date, ''%Y-%m-%d'') report_date,
equity_to_shop_count, after_sale_equity_to_shop_count, deleted_flag
from dj_car_life_staff_daily_report_huawei t
left join (
select staff_uuid 员工uuid, staff_name 员工姓名, phone_number 员工手机号 from dj_car_life_staff_info where deleted_flag = ''N''
) dclsi on t.staff_uuid = dclsi.员工uuid
) t
where deleted_flag = ''N''
and DATE_FORMAT(report_date, ''%Y-%m-%d'') between date_format(''starttimexxxxxx'', ''%Y-%m-%d'') and ''endtimexxxxxx''
group by 4s店店商户号, staff_uuid, scene_type, report_date
) t2 on t.4s店商户号 = t2.4s店店商户号 and t.员工id = t2.staff_uuid and t.场景 = t2.scene_type and t.统计时间 = t2.report_date
left join (
SELECT
t1.staff_uuid, DATE_FORMAT(t1.reception_start_time, ''%Y-%m-%d'') AS 接待时间,
(case when t1.bussiness_type=2 then 1 when t1.bussiness_type=1 then 0 end )bussiness_type,
t1.merchant_id, count(1) as ''接待次数'', AVG(t3.score) as 质检平均分
FROM (
select ifnull(员工手机号,staff_uuid)staff_uuid,reception_start_time,bussiness_type,merchant_id,id from reception_customer_info rcf
left join ( select staff_uuid 员工uuid,staff_name 员工姓名 ,phone_number 员工手机号 from dj_car_life_staff_info where deleted_flag = ''N''
)dclsi on rcf.staff_uuid=dclsi.员工uuid
)t1
LEFT JOIN inspection_badge_recordings t2 ON t1.id = t2.reception_id
LEFT JOIN inspection_conversation_batch t3 ON t2.id = t3.record_id
where t2.che_result_flag =2 and t3.score>20
and date_format (reception_start_time,''%Y-%m-%d'')between date_format(''starttimexxxxxx'',''%Y-%m-%d'') and ''endtimexxxxxx''
GROUP BY t1.staff_uuid, t1.bussiness_type, t1.merchant_id,date_format (reception_start_time,''%Y-%m-%d'')
)t6 on t.4s店商户号=t6.merchant_id and t.员工id=t6.staff_uuid and t.场景=t6.bussiness_type and t.统计时间=t6.接待时间
)t group by 4s店商户号,员工id,scene_type',
update_date = now(),
ver_desc = '9月版本: 到店量按scene_type区分业务'
WHERE sqlname = 'querySellerUserUsedipadAnalysis02'
AND deleted_flag = 'N';
### 章家宝 -----------------end--------------------
\ No newline at end of file \ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!