Commit edc47f3f authored by 魏艺敏's avatar 魏艺敏

push codes

parent 60dfe610
......@@ -123,13 +123,13 @@ FROM
)mas
left join
(--找出user_id当天活跃的第一个设备id
SELECT user_id,partition_day,
if(size(device_id_list) > 0, device_id_list [ 0 ], '') AS device_id
FROM ml.ml_c_ct_ui_user_dimen_inc_d
WHERE partition_day>=REGEXP_REPLACE(trunc(date_sub(current_date(),1),'MM'),'-','')
AND partition_day<= regexp_replace(date_sub(current_date,1),'-','')
SELECT user_id,partition_date,
if(size(device_list) > 0, device_list [ 0 ], '') AS device_id
FROM online.ml_user_updates
WHERE partition_date>=REGEXP_REPLACE(trunc(date_sub(current_date(),1),'MM'),'-','')
AND partition_date<= regexp_replace(date_sub(current_date,1),'-','')
)a
on mas.partition_date=a.partition_day and mas.device_id=a.device_id
on mas.partition_date=a.partition_date and mas.device_id=a.device_id
left join
(--私信线索总数
SELECT msg.partition_date,user_id
......@@ -144,7 +144,7 @@ FROM
)msg
GROUP BY msg.partition_date,user_id
)t1
ON a.partition_day = t1.partition_date and a.user_id=t1.user_id
ON a.partition_date = t1.partition_date and a.user_id=t1.user_id
left join
(--有效私信线索总数
SELECT msg.partition_date,user_id
......@@ -160,7 +160,7 @@ FROM
)msg
GROUP BY msg.partition_date,user_id
)t1_v
ON a.partition_day = t1_v.partition_date and a.user_id=t1_v.user_id
ON a.partition_date = t1_v.partition_date and a.user_id=t1_v.user_id
LEFT JOIN
( --电话线索总数
SELECT partition_date,user_id,count(1) AS clue_num
......@@ -175,7 +175,7 @@ FROM
)a
GROUP BY partition_date,user_id
)t2
ON a.partition_day = t2.partition_date and a.user_id=t2.user_id
ON a.partition_date = t2.partition_date and a.user_id=t2.user_id
left join
(--kyc私信
......@@ -206,7 +206,7 @@ FROM
)msg
group by msg.partition_date,user_id
)t4
on a.partition_day=t4.partition_date and a.user_id=t4.user_id
on a.partition_date=t4.partition_date and a.user_id=t4.user_id
left join
(--kyc有效私信
SELECT msg.partition_date,user_id
......@@ -237,7 +237,7 @@ FROM
)msg
group by msg.partition_date,user_id
)t4_v
on a.partition_day=t4_v.partition_date and a.user_id=t4_v.user_id
on a.partition_date=t4_v.partition_date and a.user_id=t4_v.user_id
LEFT JOIN
( --kyc电话线索总数
SELECT partition_date,user_id,count(1) as clue_num
......@@ -288,7 +288,7 @@ FROM
)a
group by partition_date,user_id
)t5
ON a.partition_day = t5.partition_date and a.user_id=t5.user_id
ON a.partition_date = t5.partition_date and a.user_id=t5.user_id
left join
(--需求自测私信
......@@ -342,7 +342,7 @@ FROM
)msg
group by msg.partition_date,user_id
)t7
on a.partition_day=t7.partition_date and a.user_id=t7.user_id
on a.partition_date=t7.partition_date and a.user_id=t7.user_id
left join
(--需求自测有效私信
SELECT msg.partition_date,user_id
......@@ -396,7 +396,7 @@ FROM
)msg
group by msg.partition_date,user_id
)t7_v
on a.partition_day=t7_v.partition_date and a.user_id=t7_v.user_id
on a.partition_date=t7_v.partition_date and a.user_id=t7_v.user_id
LEFT JOIN
( --需求自测电话线索总数
SELECT partition_date,user_id,count(1) as clue_num
......@@ -429,7 +429,7 @@ FROM
)a
group by partition_date,user_id
)t8
ON a.partition_day = t8.partition_date and a.user_id=t8.user_id
ON a.partition_date = t8.partition_date and a.user_id=t8.user_id
left join
(--t4以上商户私信线索总数
......@@ -459,7 +459,7 @@ FROM
on msg.merchant_id=b.merchant_id
GROUP BY msg.partition_date,user_id
)t10
ON a.partition_day = t10.partition_date and a.user_id=t10.user_id
ON a.partition_date = t10.partition_date and a.user_id=t10.user_id
left join
(--t4以上商户有效私信线索总数
SELECT msg.partition_date,user_id
......@@ -489,7 +489,7 @@ FROM
on msg.merchant_id=b.merchant_id
GROUP BY msg.partition_date,user_id
)t10_v
ON a.partition_day = t10_v.partition_date and a.user_id=t10_v.user_id
ON a.partition_date = t10_v.partition_date and a.user_id=t10_v.user_id
left join
(--t4以上商户电话线索总数
SELECT partition_date,user_id,count(1) AS clue_num
......@@ -518,13 +518,15 @@ FROM
on a.merchant_id=b.merchant_id
GROUP BY partition_date,user_id
)t11
ON a.partition_day = t11.partition_date and a.user_id=t11.user_id
ON a.partition_date = t11.partition_date and a.user_id=t11.user_id
group by mas.partition_date,device_os_type,active_type,grey_type
)T1
LEFT JOIN
(
SELECT t3.partition_date,a.device_os_type,'老活跃设备'as active_type,a.grey_type
,count(distinct case when t3.call_num>0 then t3.user_id end) as call_dev
SELECT t3.partition_date,a.device_os_type,a.grey_type
,case when b.active_type in ('1','2') then '新增设备'
when (b.active_type ='4' or b.active_type is null) then '老活跃设备' end as active_type
,count(distinct case when t3.call_num>0 then t3.user_id end) as call_dev
,sum(t3.call_num) as call_num
,count(distinct case when t3_v.valid_call_num>0 then t3_v.user_id end) as valid_call_dev
,sum(t3_v.valid_call_num) as valid_call_num
......@@ -553,24 +555,25 @@ LEFT JOIN
,array(case when substr(convup(setencryption(device_id,'sha-1'),16,10),-2,2)%20 = 0 then 'kyc灰度' else '非灰' end,'合计') as grey_type
FROM
(
SELECT device_id,device_os_type,a.user_id
,row_number() over(partition by device_id order by a.partition_day desc) as rn
SELECT device_id,device_os_type,a.user_id,a.partition_date
,row_number() over(partition by device_id order by a.partition_date desc) as rn
FROM
(
SELECT device_id,device_os_type,v.user_id,partition_day
FROM ml.mid_ml_c_ct_dv_device_inc_d
LATERAL VIEW EXPLODE(user_id_list) v as user_id
where partition_day>='20200801' and partition_day<=regexp_replace(date_sub(current_date(),1),'-','')
SELECT device_id,v.device_os_type,v.user_id,partition_date
FROM online.ml_device_updates
LATERAL VIEW EXPLODE(user_list) v as user_id
LATERAL VIEW EXPLODE(device_os_type) v as device_os_type
where partition_date>='20200801' and partition_date<=regexp_replace(date_sub(current_date(),1),'-','')
)a--由于要取近期该设备用过的user_id,故时间取的较长,避免用公式而将月末数据少算
join
(
SELECT partition_day,user_id
FROM ml.ml_c_ct_ui_user_dimen_inc_d
where partition_day>='20200801' and partition_day<=regexp_replace(date_sub(current_date(),1),'-','')
and size(user_phone_list)>0
group by partition_day,user_id
SELECT partition_date,user_id
FROM online.ml_user_updates
where partition_date>='20200801' and partition_date<=regexp_replace(date_sub(current_date(),1),'-','')
and phone is not null and phone <>''
group by partition_date,user_id
)b
on a.partition_day=b.partition_day and a.user_id=b.user_id
on a.partition_date=b.partition_date and a.user_id=b.user_id
)c
where rn=1
)d
......@@ -628,6 +631,18 @@ LEFT JOIN
GROUP BY user_id,partition_date
)t3
ON a.user_id=t3.user_id
left join
(
SELECT
partition_date
,device_id
,active_type
FROM online.ml_device_day_active_status
where partition_date>=REGEXP_REPLACE(trunc(date_sub(current_date(),1),'MM'),'-','')
AND partition_date<=regexp_replace(date_sub(current_date,1),'-','')
AND active_type in ('1','2','4')
)b
on t3.partition_date=b.partition_date and a.device_id=b.device_id
LEFT JOIN
( ---拨打电话线索
SELECT partition_date,user_id
......@@ -1120,9 +1135,10 @@ LEFT JOIN
GROUP BY user_id,partition_date
)t12_v
ON t3.partition_date = t12_v.partition_date and t3.user_id=t12_v.user_id
group by t3.partition_date,a.device_os_type,a.grey_type
group by t3.partition_date,a.device_os_type,a.grey_type,case when b.active_type in ('1','2') then '新增设备'
when (b.active_type ='4' or b.active_type is null) then '老活跃设备' end
)T2
on T1.partition_date=T2.partition_date
AND T1.device_os_type=T2.device_os_type
AND T1.active_type=T2.active_type
AND T1.grey_type=T2.grey_type;
AND T1.grey_type=T2.grey_type
\ No newline at end of file
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