Commit 85f385cb authored by 赵建伟's avatar 赵建伟

Merge branch 'yindanlei' into 'master'

Yindanlei

See merge request !56
parents 17aa35bf 19322a17
...@@ -184,8 +184,7 @@ LEFT JOIN ...@@ -184,8 +184,7 @@ LEFT JOIN
WHERE partition_day=regexp_replace(date_sub(current_date(),1),'-','') WHERE partition_day=regexp_replace(date_sub(current_date(),1),'-','')
AND REGEXP_REPLACE(SUBSTR(call_time,0,10), '-', '')>='20200701' AND REGEXP_REPLACE(SUBSTR(call_time,0,10), '-', '')>='20200701'
AND REGEXP_REPLACE(SUBSTR(call_time,0,10), '-', '')<=regexp_replace(date_sub(current_date(),1),'-','') AND REGEXP_REPLACE(SUBSTR(call_time,0,10), '-', '')<=regexp_replace(date_sub(current_date(),1),'-','')
--AND start_time+ interval 30 second <= release_time --通话时长大于30秒 AND release_time>start_time
AND unix_timestamp(substr(start_time,1,19))+30<=unix_timestamp(substr(release_time,1,19))
)a )a
LEFT JOIN LEFT JOIN
( (
...@@ -301,8 +300,7 @@ LEFT JOIN ...@@ -301,8 +300,7 @@ LEFT JOIN
WHERE partition_day=regexp_replace(date_sub(current_date(),1),'-','') WHERE partition_day=regexp_replace(date_sub(current_date(),1),'-','')
AND REGEXP_REPLACE(SUBSTR(call_time,0,10), '-', '')>='20200701' AND REGEXP_REPLACE(SUBSTR(call_time,0,10), '-', '')>='20200701'
AND REGEXP_REPLACE(SUBSTR(call_time,0,10), '-', '')<=regexp_replace(date_sub(current_date(),1),'-','') AND REGEXP_REPLACE(SUBSTR(call_time,0,10), '-', '')<=regexp_replace(date_sub(current_date(),1),'-','')
--AND start_time+ interval 30 second <= release_time --通话时长大于30秒 AND release_time>start_time
AND unix_timestamp(substr(start_time,1,19))+30<=unix_timestamp(substr(release_time,1,19))
)a )a
LEFT JOIN LEFT JOIN
( (
......
yeji_day=业绩基础数据
\ No newline at end of file
--***************************************************************
--*脚本名称:
--*功能: 业绩基础数据
--*业务名称: pm
--*输入数据:
--*作者: yindanlei@igengmei.com
--*更新时间:2020-09-22
--***************************************************************
--设置全局变量&UDF
SET mapreduce.job.queuename=data;
--使用bl数据库
USE pm;
--创建BL层内部表
CREATE TABLE IF NOT EXISTS pm.tl_pm_yeji_d
(
data string comment '{"chs_name":"日期","description":"","etl":"","value":"","remark":""}',
merchant_name string comment '{"chs_name":"商户名称","description":"","etl":"","value":"","remark":""}',
business_group_name string comment '{"chs_name":"商务组","description":"","etl":"","value":"","remark":""}',
business_partener_name string comment '{"chs_name":"商务名称","description":"","etl":"","value":"","remark":""}',
city_name string comment '{"chs_name":"城市","description":"","etl":"","value":"","remark":""}',
hexin_pv BIGINT comment '{"chs_name":"核心页pv","description":"","etl":"","value":"","remark":""}',
service_pv BIGINT comment '{"chs_name":"美购页pv","description":"","etl":"","value":"","remark":""}',
clue_num BIGINT comment '{"chs_name":"有效线索人次","description":"","etl":"","value":"","remark":""}',
discount BIGINT comment '{"chs_name":"总验证抽成","description":"","etl":"","value":"","remark":""}',
recharge_amount BIGINT comment '{"chs_name":"广告收款","description":"","etl":"","value":"","remark":""}',
chongzhi_amount BIGINT comment '{"chs_name":"广告消耗","description":"","etl":"","value":"","remark":""}',
all_amount BIGINT comment '{"chs_name":"广告总消耗(含返点)","description":"","etl":"","value":"","remark":""}',
cpc_amount BIGINT comment '{"chs_name":"cpc总消耗","description":"","etl":"","value":"","remark":""}',
cpc_chongzhi_amount BIGINT comment '{"chs_name":"cpc充值消耗","description":"","etl":"","value":"","remark":""}',
budget BIGINT comment '{"chs_name":"cpc商品有效预算","description":"","etl":"","value":"","remark":""}',
cpc_click_num BIGINT comment '{"chs_name":"cpc点击数","description":"","etl":"","value":"","remark":""}',
liulan_amount BIGINT comment '{"chs_name":"浏览收入","description":"","etl":"","value":"","remark":""}',
sixin_amount BIGINT comment '{"chs_name":"私信收入","description":"","etl":"","value":"","remark":""}',
service_price BIGINT comment '{"chs_name":"纯用户支付金额","description":"","etl":"","value":"","remark":""}'
)comment '业绩基础数据'
PARTITIONED BY (PARTITION_DAY STRING comment '分区日期')
ROW FORMAT DELIMITED
FIELDS TERMINATED BY '\t'
COLLECTION ITEMS TERMINATED BY '\002'
MAP KEYS TERMINATED BY '\003'
LINES TERMINATED BY '\n'
STORED AS TEXTFILE;
\ No newline at end of file
SET mapreduce.job.queuename=data;
SET mapreduce.map.memory.mb=8192;
SET mapreduce.map.java.opts=-Xmx8000m;
SET mapreduce.reduce.memory.mb=8192;
SET mapreduce.reduce.java.opts=-Xmx8000m;
set hive.auto.convert.join=true;
SET mapred.reduce.tasks=20;
SET role admin;
INSERT OVERWRITE TABLE pm.tl_pm_yeji_d PARTITION (PARTITION_DAY = ${partition_day})
SELECT nvl(nvl(nvl(nvl(t1.partition_date,t2.DATA_DAY),t3.DATA_MONTH),t4.PAY_MONTH),t5.day_month) as data
,nvl(nvl(nvl(nvl(t1.merchant_name,t2.merchant_name),t3.merchant_name),t4.merchant_name),t5.merchant_name) as merchant_name
,nvl(nvl(nvl(nvl(t1.business_group_name,t2.business_group_name),t3.business_group_name),t4.business_group_name),t5.business_group_name) as business_group_name
,nvl(nvl(nvl(nvl(t1.business_partener_name,t2.business_partener_name),t3.business_partener_name),t4.business_partener_name),t5.business_partener_name) as business_partener_name
,nvl(nvl(nvl(nvl(t1.city_name,t2.city_name),t3.city_name),t4.city_name),t5.city_name) as city_name
,nvl(hexin_pv,0) as hexin_pv
,nvl(service_pv,0) as service_pv
,nvl(clue_num,0) as clue_num
,nvl(discount,0) as discount
,nvl(recharge_amount,0) as recharge_amount
,nvl(chongzhi_amount,0) as chongzhi_amount
,nvl(all_amount,0) as all_amount
,nvl(cpc_amount,0) as cpc_amount
,nvl(cpc_chongzhi_amount,0) as cpc_chongzhi_amount
,nvl(budget,0) as budget
,nvl(cpc_click_num,0) as cpc_click_num
,nvl(liulan_amount,0) as liulan_amount
,nvl(sixin_amount,0) as sixin_amount
,nvl(service_price,0) as service_price
FROM
---核心、美购页pv
(
SELECT
a.partition_date
,merchant_name
,b.business_group_name
,b.business_partener_name
,city_name
,SUM(hexin_pv) as hexin_pv
,SUM(service_pv) as service_pv
FROM
(
SELECT --之前是根据merchant_id算的,有重复,如果按doctor_id值不会重复
partition_date,doctor_id,SUM(pv_num) as hexin_pv,SUM(case when business_type = 'service' then pv_num end) as service_pv
FROM online.ml_doctor_event_indic_day
WHERE partition_date=REGEXP_REPLACE(date_sub(current_date(),1),'-','')
AND merchant_id IS NOT NULL
AND merchant_id <> ''
AND business_type IN ('service','org', 'doctor')
AND data_type = 'pv'
AND cl_id <> ''
AND cl_id <> '0'
GROUP BY partition_date,doctor_id
)a
LEFT JOIN
( --商务归属1009更新
--!! 注意:这里的日期变量设置为当前日期的前一天,定时任务为每月第一天,故查询的为上月最后一天的归属
SELECT
doctor_id,merchant_name,business_group_name,business_partener_name,city_name
FROM
online.ml_doctor_relation_dimen_day
WHERE partition_date =REGEXP_REPLACE(date_sub(current_date(),1),'-','')
GROUP BY doctor_id,merchant_name,business_group_name,business_partener_name,city_name
)b
ON a.doctor_id=b.doctor_id
GROUP BY a.partition_date
,merchant_name
,b.business_group_name
,b.business_partener_name
,city_name
)t1
FULL JOIN
(
SELECT DATA_DAY
,merchant_name
,b.business_group_name
,b.business_partener_name
,city_name
,SUM(clue_num) as clue_num
FROM
(--有效线索分日数据
SELECT
DATA_DAY,merchant_id,count(1) AS clue_num
FROM
(
SELECT NVL(T1.USER_ID,T2.USER_ID) AS USER_ID,
NVL(T1.merchant_id,T2.merchant_id) AS merchant_id,
NVL(T1.DATA_MONTH,T2.CALL_MONTH) AS DATA_MONTH,
least(NVL(DATA_DAY,'99999999'),NVL(FIRST_CALL_DATE,'99999999')) AS DATA_DAY,
NVL(T1.CONSULT_NUM,0) AS CONSULT_NUM,
NVL(T1.PAY_NUM,0) AS PAY_NUM,
NVL(T2.call_num,0) AS CALL_NUM
FROM
(
SELECT
NVL(T3.USER_ID,T4.USER_ID) AS USER_ID,
NVL(T3.merchant_id,T4.merchant_id) AS merchant_id,
NVL(T3.CONSULT_MONTH,T4.PAY_MONTH) AS DATA_MONTH,
least(NVL(first_consult_date,'99999999'),NVL(FIRST_PAY_DATE,'99999999')) AS DATA_DAY,
NVL(T3.CONSULT_NUM,0) AS CONSULT_NUM,
NVL(T4.PAY_NUM,0) AS PAY_NUM
FROM
(
SELECT
user_id
,merchant_id
,substr(partition_day,1,6) AS consult_month
,min(partition_day) AS first_consult_date
,1 AS consult_num
FROM ml.ML_C_ET_MSG_CONVERSATION_DIMEN_INC_D
WHERE
partition_day =REGEXP_REPLACE(date_sub(current_date(),1),'-','')
AND is_valid='true'
AND merchant_id IS NOT NULL
GROUP BY user_id,merchant_id,substr(partition_day,1,6)
)T3
FULL JOIN
(
SELECT
T.USER_ID,
T.merchant_id,
regexp_replace(SUBSTR(T.PAY_DATE,1,7),'-','') AS PAY_MONTH,
MIN(regexp_replace(SUBSTR(T.PAY_DATE,1,10),'-','')) AS FIRST_PAY_DATE,
1 AS PAY_NUM
FROM ONLINE.ML_TRADE_ORDER_DETAIL_DAY T
WHERE
T.PARTITION_DATE = REGEXP_REPLACE(date_sub(current_date(),1),'-','')
AND regexp_replace(substr(T.PAY_DATE,1,10),'-','') =REGEXP_REPLACE(date_sub(current_date(),1),'-','')
AND T.is_pure_user='true'
GROUP BY T.USER_ID,T.merchant_id,regexp_replace(SUBSTR(T.PAY_DATE,1,7),'-','')
) T4
ON T3.USER_ID = T4.USER_ID AND T3.merchant_id = T4.merchant_id AND T3.CONSULT_MONTH = T4.PAY_MONTH
GROUP BY NVL(T3.USER_ID,T4.USER_ID),NVL(T3.merchant_id,T4.merchant_id),NVL(T3.CONSULT_MONTH,T4.PAY_MONTH),
least(NVL(first_consult_date,'99999999'),NVL(FIRST_PAY_DATE,'99999999')),NVL(T3.CONSULT_NUM,0),NVL(T4.PAY_NUM,0)
)T1
FULL JOIN
(
SELECT user_id,merchant_id,regexp_replace(SUBSTR(a.partition_date,1,6),'-','') AS CALL_MONTH,
MIN(partition_date) as FIRST_CALL_DATE,1 AS call_num
FROM
(
SELECT sub_id,REGEXP_REPLACE(SUBSTR(call_time,0,10), '-', '') as partition_date
FROM tl.tl_gm_sl_ali_virtual_phone_call_detail --通话记录表,call_type呼叫类型
WHERE partition_day=regexp_replace(date_sub(current_date(),1),'-','')
AND REGEXP_REPLACE(SUBSTR(call_time,0,10), '-', '')=REGEXP_REPLACE(date_sub(current_date(),1),'-','')
--AND start_time+ interval 30 second <= release_time --通话时长大于30秒
AND release_time>start_time
)a
LEFT JOIN
(
SELECT id,sub_id
FROM tl.tl_gm_sl_ali_virtual_phone_binding --阿里记录表
WHERE partition_day=REGEXP_REPLACE(date_sub(current_date(),1),'-','')
)b
ON a.sub_id = b.sub_id
LEFT JOIN
(
SELECT id,platform_binding_id
FROM tl.tl_gm_sl_virtual_phone_binding
WHERE partition_day=REGEXP_REPLACE(date_sub(current_date(),1),'-','')
)c
ON b.id = c.platform_binding_id
LEFT JOIN
(
SELECT phone_binding_id,lead_task_id
FROM tl.tl_gm_sl_lead_task_phone_binding
WHERE partition_day=REGEXP_REPLACE(date_sub(current_date(),1),'-','')
)d
ON c.id = d.phone_binding_id
JOIN
(
SELECT id,user_id,merchant_id
FROM tl.tl_gm_sl_lead_task --线索任务表(用户点击授权后记入该表)
WHERE partition_day=REGEXP_REPLACE(date_sub(current_date(),1),'-','')
AND source='2' --用户行为电话授权
AND (USER_ID is NOT NULL or USER_ID <>'')
)e
ON d.lead_task_id = e.id
GROUP BY user_id,merchant_id,regexp_replace(SUBSTR(a.partition_date,1,6),'-','')
)T2
ON T1.USER_ID = T2.USER_ID AND T1.merchant_id = T2.merchant_id AND T1.DATA_MONTH = T2.CALL_MONTH
)T1
GROUP BY DATA_DAY,merchant_id
)t3
LEFT JOIN
( --商务归属1009更新
--!! 注意:这里的日期变量设置为当前日期的前一天,定时任务为每月第一天,故查询的为上月最后一天的归属
SELECT
merchant_id,merchant_name,business_group_name,business_partener_name,city_name
FROM
online.ml_doctor_relation_dimen_day
WHERE partition_date =REGEXP_REPLACE(date_sub(current_date(),1),'-','')
GROUP BY merchant_id,merchant_name,business_group_name,business_partener_name,city_name
)b
ON t3.merchant_id=b.merchant_id
GROUP BY DATA_DAY
,merchant_name
,b.business_group_name
,b.business_partener_name
,city_name
)t2
ON t1.partition_date=t2.DATA_DAY AND t1.merchant_name=t2.merchant_name
AND t1.business_group_name=t2.business_group_name AND t1.business_partener_name=t2.business_partener_name
AND t1.city_name=t2.city_name
FULL JOIN
(
SELECT nvl(nvl(t1.month,t2.month),t3.month) as DATA_MONTH
,nvl(nvl(t1.merchant_name,t2.merchant_name),t3.merchant_name) as merchant_name
,nvl(nvl(t1.business_group_name,t2.business_group_name),t3.business_group_name) as business_group_name
,nvl(nvl(t1.business_partener_name,t2.business_partener_name),t3.business_partener_name) as business_partener_name
,nvl(nvl(t1.city_name,t2.city_name),t3.city_name) as city_name
,nvl(discount,0) as discount
,nvl(recharge_amount,0) as recharge_amount
,nvl(all_amount,0) as all_amount
,nvl(chongzhi_amount,0) as chongzhi_amount
,nvl(cpc_amount,0) as cpc_amount
,nvl(cpc_chongzhi_amount,0) as cpc_chongzhi_amount
,nvl(cpc_click_num,0) as cpc_click_num
,nvl(liulan_amount,0) as liulan_amount
,nvl(sixin_amount,0) as sixin_amount
FROM
(
--佣金(订单验证抽成+一般补单(常规补单+罚款)+买单+剔除转诊关联的订单
SELECT month,merchant_name,business_group_name,business_partener_name,city_name,SUM(money1) as discount
FROM
(
SELECT SUBSTR(REGEXP_REPLACE(SUBSTR(validate_time, 1, 10), '-', ''),1,8) as month,doctor_id,sum(discount) as money1
FROM online.ml_trade_order_detail_day --美购交易表
WHERE partition_date = REGEXP_REPLACE(date_sub(current_date(),1),'-','')
AND REGEXP_REPLACE(SUBSTR(validate_time, 1, 10), '-', '') = REGEXP_REPLACE(date_sub(current_date(),1),'-','')
AND status <> '3' --去除已退款
AND is_referral_order ='false' --去除转诊关联的订单
GROUP BY REGEXP_REPLACE(SUBSTR(validate_time, 1, 10), '-', ''),doctor_id
UNION ALL
SELECT SUBSTR(REGEXP_REPLACE(SUBSTR(created_time, 1, 10), '-', ''),1,8) as month,doctor_id,sum(amount) as money1
FROM online.tl_hdfs_budanluru_view --补单录入表
WHERE partition_date = REGEXP_REPLACE(date_sub(current_date(),1),'-','')
AND REGEXP_REPLACE(SUBSTR(created_time, 1, 10), '-', '') = REGEXP_REPLACE(date_sub(current_date(),1),'-','')
AND status = 0 --已录入
AND type in ('0','2') --常规补单和罚款
GROUP BY REGEXP_REPLACE(SUBSTR(created_time, 1, 10), '-', ''),doctor_id
UNION ALL
SELECT SUBSTR(REGEXP_REPLACE(SUBSTR(created_time, 1, 10), '-', ''),1,8) as month,doctor_id,sum(discount_cent)/100 as money1
FROM online.tl_maidan_order_view --买单表
WHERE partition_date = REGEXP_REPLACE(date_sub(current_date(),1),'-','')
AND REGEXP_REPLACE(SUBSTR(created_time, 1, 10), '-', '') = REGEXP_REPLACE(date_sub(current_date(),1),'-','')
AND status ='1'
GROUP BY REGEXP_REPLACE(SUBSTR(created_time, 1, 10), '-', ''),doctor_id
)ord
LEFT JOIN
(
SELECT doctor_id,city_name,business_group_name,business_partener_name,merchant_name
FROM online.ml_doctor_relation_dimen_day
WHERE partition_date=REGEXP_REPLACE(date_sub(current_date(),1),'-','')
GROUP BY doctor_id,city_name,business_group_name,business_partener_name,merchant_name
)doc
on ord.doctor_id = doc.doctor_id
GROUP BY month,merchant_name,business_group_name,business_partener_name,city_name
)t1
FULL JOIN
( --广告充值
SELECT month,merchant_name,business_group_name,business_partener_name,city_name,SUM(recharge_amount) as recharge_amount
FROM
(
SELECT SUBSTR(partition_day,1,8) as month,merchant_id,sum(proportion_recharge_amount) as recharge_amount --当天充值金额
FROM ml.ml_c_ct_mc_merchant_indic_d
WHERE partition_day = REGEXP_REPLACE(date_sub(current_date(),1),'-','')
GROUP BY SUBSTR(partition_day,1,8),merchant_id
)gg
LEFT JOIN
(
SELECT merchant_id,city_name,business_group_name,business_partener_name,merchant_name
FROM online.ml_doctor_relation_dimen_day
WHERE partition_date=REGEXP_REPLACE(date_sub(current_date(),1),'-','')
AND doctor_is_merchant = 'true'
GROUP BY merchant_id,city_name,business_group_name,business_partener_name,merchant_name
)doc
on gg.merchant_id = doc.merchant_id
GROUP BY month,merchant_name,business_group_name,business_partener_name,city_name
)t2
on t1.month=t2.month AND t1.merchant_name=t2.merchant_name AND t1.business_group_name=t2.business_group_name AND t1.business_partener_name=t2.business_partener_name AND t1.city_name=t2.city_name
FULL JOIN
(--广告充值消耗(报表口径)
SELECT month,merchant_name,business_group_name,business_partener_name,city_name,SUM(all_amount) as all_amount,SUM(chongzhi_amount) as chongzhi_amount
,SUM(cpc_amount) as cpc_amount,SUM(cpc_chongzhi_amount) as cpc_chongzhi_amount,SUM(cpc_click_num) as cpc_click_num,SUM(liulan_amount) as liulan_amount,SUM(sixin_amount) as sixin_amount
FROM
(
SELECT SUBSTR(partition_day,1,8) as month,merchant_id
,SUM(CASE WHEN advertise_type = 'cpc' AND advertise_calculate_type = 'cpc_flownext' THEN
proportion_expend_recharge_amount
WHEN advertise_type = 'cpt' AND advertise_calculate_type = 'cpt_schedule' THEN
proportion_expend_recharge_amount
WHEN advertise_type IN ('browse', 'message', 'valueadded','rechargededuction') THEN
proportion_expend_recharge_amount
WHEN advertise_type = 'adjustment' AND advertise_calculate_type ='adjustment_flow' THEN
proportion_expend_recharge_amount
ELSE
0
END) chongzhi_amount --广告充值总消耗(等比例)
,SUM(CASE WHEN advertise_type = 'cpc' AND advertise_calculate_type = 'cpc_flownext' THEN
proportion_expend_amount
WHEN advertise_type = 'cpt' AND advertise_calculate_type = 'cpt_schedule' THEN
proportion_expend_amount
WHEN advertise_type IN ('browse', 'message', 'valueadded','rechargededuction') THEN
proportion_expend_amount
WHEN advertise_type = 'adjustment' AND advertise_calculate_type ='adjustment_flow' THEN
proportion_expend_amount
ELSE
0
END) all_amount --广告总消耗(含返点等比例)
,SUM(CASE WHEN advertise_type = 'cpc' AND advertise_calculate_type = 'cpc_flownext' THEN proportion_expend_amount END) as cpc_amount --cpc总消耗
,SUM(CASE WHEN advertise_type = 'cpc' AND advertise_calculate_type = 'cpc_flownext' THEN proportion_expend_recharge_amount END) as cpc_chongzhi_amount --cpc充值消耗
,SUM(case when advertise_type = 'cpc' AND advertise_business_type in('service') and advertise_calculate_type='cpc_log' then cpc_click_num end) cpc_click_num ---当天cpc商品点击量
,SUM(CASE WHEN advertise_type='browse' THEN proportion_expend_recharge_amount END) as liulan_amount --浏览收入(不含返点)
,SUM(CASE WHEN advertise_type='message' THEN proportion_expend_recharge_amount END) as sixin_amount --私信收入(不含返点)
from ml.ml_c_ct_mc_merchantadclassify_indic_d
where partition_day=REGEXP_REPLACE(date_sub(current_date(),1),'-','')
group by SUBSTR(partition_day,1,8),merchant_id
)gg
LEFT JOIN
(
SELECT merchant_id,city_name,business_group_name,business_partener_name,merchant_name
FROM online.ml_doctor_relation_dimen_day
WHERE partition_date=REGEXP_REPLACE(date_sub(current_date(),1),'-','')
AND doctor_is_merchant = 'true'
GROUP BY merchant_id,city_name,business_group_name,business_partener_name,merchant_name
)doc
on gg.merchant_id = doc.merchant_id
GROUP BY month,merchant_name,business_group_name,business_partener_name,city_name
)t3
on nvl(t1.month,t2.month)=t3.month
and nvl(t1.merchant_name,t2.merchant_name)=t3.merchant_name
AND nvl(t1.business_group_name,t2.business_group_name)=t3.business_group_name
AND nvl(t1.business_partener_name,t2.business_partener_name)=t3.business_partener_name
AND nvl(t1.city_name,t2.city_name)=t3.city_name
)t3
on nvl(t1.partition_date,t2.DATA_DAY)=t3.DATA_MONTH
and nvl(t1.merchant_name,t2.merchant_name)=t3.merchant_name
AND nvl(t1.business_group_name,t2.business_group_name)=t3.business_group_name
AND nvl(t1.business_partener_name,t2.business_partener_name)=t3.business_partener_name
AND nvl(t1.city_name,t2.city_name)=t3.city_name
FULL JOIN
(
SELECT SUBSTR(pay_date, 1, 8) as PAY_MONTH,merchant_name,business_group_name,business_partener_name,city_name,SUM(service_price) as service_price
FROM
(
SELECT REGEXP_REPLACE(SUBSTR(pay_time, 1, 10), '-', '') as pay_date,doctor_id,sum(service_price) as service_price
FROM online.ml_trade_order_detail_day --美购交易表(梦雨新做)
WHERE partition_date = REGEXP_REPLACE(date_sub(current_date(),1),'-','')
AND REGEXP_REPLACE(SUBSTR(pay_time, 1, 10), '-', '') = REGEXP_REPLACE(date_sub(current_date(),1),'-','')
AND is_pure_user = 'true' --取纯用户
GROUP BY REGEXP_REPLACE(SUBSTR(pay_time, 1, 10), '-', ''),doctor_id
)ord
LEFT JOIN
(
SELECT doctor_id,city_name,business_group_name,business_partener_name,merchant_name
FROM online.ml_doctor_relation_dimen_day
WHERE partition_date=REGEXP_REPLACE(date_sub(current_date(),1),'-','')
GROUP BY doctor_id,city_name,business_group_name,business_partener_name,merchant_name
)doc
on ord.doctor_id = doc.doctor_id
GROUP BY SUBSTR(pay_date, 1, 8),merchant_name,business_group_name,business_partener_name,city_name
)t4
on nvl(nvl(t1.partition_date,t2.DATA_DAY),t3.DATA_MONTH)=t4.PAY_MONTH
and nvl(nvl(t1.merchant_name,t2.merchant_name),t3.merchant_name) =t4.merchant_name
AND nvl(nvl(t1.business_group_name,t2.business_group_name),t3.business_group_name)=t4.business_group_name
AND nvl(nvl(t1.business_partener_name,t2.business_partener_name),t3.business_partener_name)=t4.business_partener_name
AND nvl(nvl(t1.city_name,t2.city_name),t3.city_name)=t4.city_name
FULL JOIN
(
SELECT SUBSTR(day_id, 1, 8) as day_month,merchant_name,business_group_name,business_partener_name,city_name,SUM(budget) as budget
FROM
(
SELECT T1.day_id,T1.merchant_doctor_id,case when merchant_budget>=tot_service_budget then tot_service_budget else merchant_budget end as budget
FROM
(
SELECT
clicklog.create_time AS day_id
,clicklog.merchant_doctor_id
,max(merchant_budget) as merchant_budget --商户预算
FROM
(
SELECT id,promote_id,price,service_budget,merchant_budget,merchant_doctor_id,regexp_replace(substr(create_time,1,10),'-','') as create_time,recharge
FROM online.tl_hdfs_cpc_clicklog_view
WHERE partition_date=REGEXP_REPLACE(date_sub(current_date(),1),'-','')
AND regexp_replace(substr(create_time,1,10),'-','')= REGEXP_REPLACE(date_sub(current_date(),1),'-','')
)clicklog
group by clicklog.create_time,clicklog.merchant_doctor_id
)T1
LEFT JOIN
(
SELECT
day_id
,merchant_doctor_id
,sum(service_budget) as tot_service_budget
FROM
(
SELECT
clicklog.create_time AS day_id
,clicklog.merchant_doctor_id,clicklog.service_id
,max(service_budget) as service_budget
FROM
(
SELECT id,promote_id,price,service_budget,merchant_budget,merchant_doctor_id,service_id,regexp_replace(substr(create_time,1,10),'-','') as create_time
FROM online.tl_hdfs_cpc_clicklog_view
WHERE partition_date=REGEXP_REPLACE(date_sub(current_date(),1),'-','')
AND regexp_replace(substr(create_time,1,10),'-','')= REGEXP_REPLACE(date_sub(current_date(),1),'-','')
)clicklog
GROUP BY clicklog.create_time,clicklog.merchant_doctor_id,clicklog.service_id
)service_budget
GROUP BY day_id,merchant_doctor_id
)T2
ON T1.day_id=T2.day_id
AND T1.merchant_doctor_id=T2.merchant_doctor_id
)ord
LEFT JOIN
(
SELECT merchant_doctor_id,merchant_name,business_group_name,business_partener_name,city_name
FROM online.ml_doctor_relation_dimen_day
WHERE partition_date=REGEXP_REPLACE(date_sub(current_date(),1),'-','')
AND doctor_is_merchant='true'
group by merchant_doctor_id,merchant_name,business_group_name,business_partener_name,city_name
)doc
on ord.merchant_doctor_id = doc.merchant_doctor_id
GROUP BY SUBSTR(day_id, 1, 8),merchant_name,business_group_name,business_partener_name,city_name
)t5
on nvl(nvl(nvl(t1.partition_date,t2.DATA_DAY),t3.DATA_MONTH),t4.PAY_MONTH)=t5.day_month
and nvl(nvl(nvl(t1.merchant_name,t2.merchant_name),t3.merchant_name),t4.merchant_name)=t5.merchant_name
AND nvl(nvl(nvl(t1.business_group_name,t2.business_group_name),t3.business_group_name),t4.business_group_name)=t5.business_group_name
AND nvl(nvl(nvl(t1.business_partener_name,t2.business_partener_name),t3.business_partener_name),t4.business_partener_name)=t5.business_partener_name
AND nvl(nvl(nvl(t1.city_name,t2.city_name),t3.city_name),t4.city_name)=t5.city_name
order by data desc
#step1_1.job #step1_1.job
type=command type=command
command=sh /home/bi/bi-report/lib/shell/waitsuccess.sh hive online ml_device_day_active_status command=sh /home/bi/bi-report/lib/shell/waitsuccess.sh hive online ml_doctor_event_indic_day
\ No newline at end of file \ No newline at end of file
#step1_12.job #step1_10.job
type=command type=command
command=sh /home/bi/bi-report/lib/shell/waitsuccess.sh hive online tl_hdfs_doctor_view command=sh /home/bi/bi-report/lib/shell/waitsuccess.sh hive online tl_hdfs_budanluru_view
\ No newline at end of file \ No newline at end of file
#step1_11.job #step1_11.job
type=command type=command
command=sh /home/bi/bi-report/lib/shell/waitsuccess.sh hive online ml_user_updates command=sh /home/bi/bi-report/lib/shell/waitsuccess.sh hive online tl_maidan_order_view
\ No newline at end of file \ No newline at end of file
#step1_12.job
type=command
command=sh /home/bi/bi-report/lib/shell/waitsuccess.sh hive ml ml_c_ct_mc_merchant_indic_d
\ No newline at end of file
#step1_13.job #step1_13.job
type=command type=command
command=sh /home/bi/bi-report/lib/shell/waitsuccess.sh hive ml ml_c_ct_ui_user_dimen_d command=sh /home/bi/bi-report/lib/shell/waitsuccess.sh hive ml ml_c_ct_mc_merchantadclassify_indic_d
\ No newline at end of file \ No newline at end of file
#step1_14.job #step1_14.job
type=command type=command
command=sh /home/bi/bi-report/lib/shell/waitsuccess.sh hive online ml_user_history_detail command=sh /home/bi/bi-report/lib/shell/waitsuccess.sh hive online tl_hdfs_cpc_clicklog_view
\ No newline at end of file \ No newline at end of file
#step1_2.job #step1_2.job
type=command type=command
command=sh /home/bi/bi-report/lib/shell/waitsuccess.sh hive online ml_device_updates command=sh /home/bi/bi-report/lib/shell/waitsuccess.sh hive online ml_doctor_relation_dimen_day
\ No newline at end of file \ No newline at end of file
#step1_5.job #step1_3.job
type=command type=command
command=sh /home/bi/bi-report/lib/shell/waitsuccess.sh hive ml ML_C_ET_MSG_CONVERSATION_DIMEN_INC_D command=sh /home/bi/bi-report/lib/shell/waitsuccess.sh hive ml ML_C_ET_MSG_CONVERSATION_DIMEN_INC_D
\ No newline at end of file
#step1_4.job #step1_4.job
type=command type=command
command=sh /home/bi/bi-report/lib/shell/waitsuccess.sh hive online ml_trade_order_detail_day command=sh /home/bi/bi-report/lib/shell/waitsuccess.sh hive online ML_TRADE_ORDER_DETAIL_DAY
\ No newline at end of file \ No newline at end of file
#step1_10.job #step1_5.job
type=command type=command
command=sh /home/bi/bi-report/lib/shell/waitsuccess.sh hive tl tl_gm_sl_lead_task command=sh /home/bi/bi-report/lib/shell/waitsuccess.sh hive tl tl_gm_sl_ali_virtual_phone_call_detail
\ No newline at end of file \ No newline at end of file
#step1_6.job #step1_6.job
type=command type=command
command=sh /home/bi/bi-report/lib/shell/waitsuccess.sh hive tl tl_gm_sl_ali_virtual_phone_call_detail command=sh /home/bi/bi-report/lib/shell/waitsuccess.sh hive tl tl_gm_sl_ali_virtual_phone_binding
\ No newline at end of file \ No newline at end of file
#step1_7.job #step1_7.job
type=command type=command
command=sh /home/bi/bi-report/lib/shell/waitsuccess.sh hive tl tl_gm_sl_ali_virtual_phone_binding command=sh /home/bi/bi-report/lib/shell/waitsuccess.sh hive tl tl_gm_sl_virtual_phone_binding
\ No newline at end of file \ No newline at end of file
#step1_8.job #step1_8.job
type=command type=command
command=sh /home/bi/bi-report/lib/shell/waitsuccess.sh hive tl tl_gm_sl_virtual_phone_binding command=sh /home/bi/bi-report/lib/shell/waitsuccess.sh hive tl tl_gm_sl_lead_task_phone_binding
\ No newline at end of file \ No newline at end of file
#step1_9.job #step1_9.job
type=command type=command
command=sh /home/bi/bi-report/lib/shell/waitsuccess.sh hive tl tl_gm_sl_lead_task_phone_binding command=sh /home/bi/bi-report/lib/shell/waitsuccess.sh hive tl tl_gm_sl_lead_task
\ No newline at end of file \ No newline at end of file
#step2.job #step2.job
type=command type=command
dependencies=step1_1,step1_2,step1_3,step1_4,step1_5,step1_6,step1_7,step1_8,step1_9,step1_10,step1_11,step1_12,step1_13,step1_14,step1_15,step1_16 dependencies=step1_1,step1_2,step1_3,step1_4,step1_5,step1_6,step1_7,step1_8,step1_9,step1_10,step1_11,step1_12,step1_13,step1_14
command=sh /home/bi/bi-report/lib/shell/hive fangan_day command=sh /home/bi/bi-report/lib/shell/hive yeji_day
\ No newline at end of file \ No newline at end of file
#step3.job
type=command
dependencies=step2
command=curl -X GET http://localhost:8553/api/report/email/yeji_day/jiaweijie@igengmei.com/zhanghaoyu@igengmei.com,cp-sunyinghe@igengmei.com,yindanlei@igengmei.com
\ No newline at end of file
--业绩基础数据
SELECT
data AS `日期`
,merchant_name AS `商户名称`
,business_group_name AS `商务组`
,business_partener_name AS `商务名称`
,city_name AS `城市`
,hexin_pv AS `核心页pv`
,service_pv AS `美购页pv`
,clue_num AS `有效线索人次`
,discount AS `总验证抽成`
,recharge_amount AS `广告收款`
,chongzhi_amount AS `广告消耗`
,all_amount AS `广告总消耗(含返点)`
,cpc_amount AS `cpc总消耗`
,cpc_chongzhi_amount AS `cpc充值消耗`
,budget AS `cpc商品有效预算`
,cpc_click_num AS `cpc点击数`
,liulan_amount AS `浏览收入`
,sixin_amount AS `私信收入`
,service_price AS `纯用户支付金额`
FROM pm.tl_pm_yeji_d
where partition_day=regexp_replace(DATE_SUB(current_date,1) ,'-','')
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment