Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
B
bi-report
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
data
bi-report
Commits
e6e2a254
Commit
e6e2a254
authored
Aug 17, 2020
by
魏艺敏
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
push codes
parent
8e3d449c
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
1049 additions
and
927 deletions
+1049
-927
clue_daily.sql
pm/clue_daily/etl/clue_daily.sql
+1026
-919
clue_daily.zip
pm/clue_daily/job/clue_daily.zip
+0
-0
step1_13.job
pm/clue_daily/job/step1_13.job
+4
-0
step1_4.job
pm/clue_daily/job/step1_4.job
+2
-2
clue_daily.sql
pm/clue_daily/report/clue_daily.sql
+3
-3
search_related.sql
pm/search_related/etl/search_related.sql
+14
-3
No files found.
pm/clue_daily/etl/clue_daily.sql
View file @
e6e2a254
SET
mapreduce
.
job
.
queuename
=
data
;
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
;
SET
role
admin
;
--线索日报
--线索日报
ADD
JAR
hdfs
:
///
user
/
hive
/
share
/
lib
/
udf
/
hive
-
udf
-
1
.
0
-
SNAPSHOT
.
jar
;
ADD
JAR
hdfs
:
///
user
/
hive
/
share
/
lib
/
udf
/
hive
-
udf
-
1
.
0
-
SNAPSHOT
.
jar
;
CREATE
TEMPORARY
FUNCTION
convup
AS
'com.gmei.hive.common.udf.UDFConvUpgrade'
;
CREATE
TEMPORARY
FUNCTION
convup
AS
'com.gmei.hive.common.udf.UDFConvUpgrade'
;
CREATE
TEMPORARY
FUNCTION
setencryption
AS
'com.gmei.hive.common.udf.UDFStringSetEncryption'
;
CREATE
TEMPORARY
FUNCTION
setencryption
AS
'com.gmei.hive.common.udf.UDFStringSetEncryption'
;
SELECT
mas
.
partition_date
as
day_id
INSERT
OVERWRITE
TABLE
pm
.
tl_pm_userclue_d
PARTITION
(
PARTITION_DAY
=
${
partition_day
}
)
SELECT
T1
.
partition_date
as
day_id
,
T1
.
device_os_type
,
T1
.
active_type
,
T1
.
grey_type
,
dau
,
user_num
,
msg_dev
,
msg_num
,
valid_msg_dev
,
valid_msg_num
,
clue_dev
,
clue_num
,
call_dev
,
call_num
,
valid_call_dev
,
valid_call_num
,
msg_dev_4
,
msg_num_4
,
valid_msg_dev_4
,
valid_msg_num_4
,
clue_dev_4
,
clue_num_4
,
call_dev_4
,
call_num_4
,
valid_call_dev_4
,
valid_call_num_4
,
msg_dev_kyc
,
msg_num_kyc
,
valid_msg_dev_kyc
,
valid_msg_num_kyc
,
clue_dev_kyc
,
clue_num_kyc
,
call_dev_kyc
,
call_num_kyc
,
valid_call_dev_kyc
,
valid_call_num_kyc
,
msg_dev_qa
,
msg_num_qa
,
valid_msg_dev_qa
,
valid_msg_num_qa
,
clue_dev_qa
,
clue_num_qa
,
call_dev_qa
,
call_num_qa
,
valid_call_dev_qa
,
valid_call_num_qa
FROM
(
SELECT
mas
.
partition_date
as
partition_date
,
device_os_type
,
device_os_type
,
active_type
,
active_type
,
grey_type
,
grey_type
,
nvl
(
count
(
distinct
mas
.
device_id
),
0
)
as
dau
,
count
(
distinct
mas
.
device_id
)
as
dau
,
nvl
(
count
(
distinct
a
.
user_id
),
0
)
as
user_num
,
count
(
distinct
a
.
user_id
)
as
user_num
,
nvl
(
count
(
distinct
case
when
t1
.
msg_num
>
0
then
t1
.
user_id
end
),
0
)
msg_dev
,
count
(
distinct
case
when
t1
.
msg_num
>
0
then
t1
.
user_id
end
)
msg_dev
,
nvl
(
sum
(
t1
.
msg_num
),
0
)
msg_num
,
sum
(
t1
.
msg_num
)
msg_num
,
nvl
(
count
(
distinct
case
when
t1_v
.
valid_msg_num
>
0
then
t1_v
.
user_id
end
),
0
)
valid_msg_dev
,
count
(
distinct
case
when
t1_v
.
valid_msg_num
>
0
then
t1_v
.
user_id
end
)
valid_msg_dev
,
nvl
(
sum
(
t1_v
.
valid_msg_num
),
0
)
valid_msg_num
,
sum
(
t1_v
.
valid_msg_num
)
as
valid_msg_num
,
nvl
(
count
(
distinct
case
when
t2
.
clue_num
>
0
then
t2
.
user_id
end
),
0
)
clue_dev
,
count
(
distinct
case
when
t2
.
clue_num
>
0
then
t2
.
user_id
end
)
as
clue_dev
,
nvl
(
sum
(
t2
.
clue_num
),
0
)
as
clue_num
,
sum
(
t2
.
clue_num
)
as
clue_num
,
nvl
(
count
(
distinct
case
when
t3
.
call_num
>
0
then
t3
.
user_id
end
),
0
)
call_dev
,
nvl
(
sum
(
t3
.
call_num
),
0
)
call_num
,
nvl
(
count
(
distinct
case
when
t3_v
.
valid_call_num
>
0
then
t3_v
.
user_id
end
),
0
)
valid_call_dev
,
nvl
(
sum
(
t3_v
.
valid_call_num
),
0
)
valid_call_num
,
nvl
(
count
(
distinct
case
when
t10
.
msg_num
>
0
then
t10
.
user_id
end
),
0
)
msg_dev_4
,
nvl
(
sum
(
t10
.
msg_num
),
0
)
msg_num_4
,
nvl
(
count
(
distinct
case
when
t10_v
.
valid_msg_num
>
0
then
t10_v
.
user_id
end
),
0
)
valid_msg_dev_4
,
nvl
(
sum
(
t10_v
.
valid_msg_num
),
0
)
as
valid_msg_num_4
,
nvl
(
count
(
distinct
case
when
t11
.
clue_num
>
0
then
t11
.
user_id
end
),
0
)
as
clue_dev_4
,
nvl
(
sum
(
t11
.
clue_num
),
0
)
as
clue_num_4
,
nvl
(
count
(
distinct
case
when
t12
.
call_num
>
0
then
t12
.
user_id
end
),
0
)
as
call_dev_4
,
nvl
(
sum
(
t12
.
call_num
),
0
)
as
call_num_4
,
nvl
(
count
(
distinct
case
when
t12_v
.
valid_call_num
>
0
then
t12_v
.
user_id
end
),
0
)
as
valid_call_dev_4
,
nvl
(
sum
(
t12_v
.
valid_call_num
),
0
)
as
valid_call_num_4
,
nvl
(
count
(
distinct
case
when
t4
.
msg_num
>
0
then
t4
.
user_id
end
),
0
)
msg_dev_kyc
,
count
(
distinct
case
when
t10
.
msg_num
>
0
then
t10
.
user_id
end
)
msg_dev_4
,
nvl
(
sum
(
t4
.
msg_num
),
0
)
msg_num_kyc
,
sum
(
t10
.
msg_num
)
msg_num_4
,
nvl
(
count
(
distinct
case
when
t4_v
.
valid_msg_num
>
0
then
t4_v
.
user_id
end
),
0
)
valid_msg_dev_kyc
,
count
(
distinct
case
when
t10_v
.
valid_msg_num
>
0
then
t10_v
.
user_id
end
)
valid_msg_dev_4
,
nvl
(
sum
(
t4_v
.
valid_msg_num
),
0
)
as
valid_msg_num_kyc
,
sum
(
t10_v
.
valid_msg_num
)
as
valid_msg_num_4
,
nvl
(
count
(
distinct
case
when
t5
.
clue_num
>
0
then
t5
.
user_id
end
),
0
)
as
clue_dev_kyc
,
count
(
distinct
case
when
t11
.
clue_num
>
0
then
t11
.
user_id
end
)
as
clue_dev_4
,
nvl
(
sum
(
t5
.
clue_num
),
0
)
as
clue_num_kyc
,
sum
(
t11
.
clue_num
)
as
clue_num_4
,
nvl
(
count
(
distinct
case
when
t6
.
call_num
>
0
then
t6
.
user_id
end
),
0
)
as
call_dev_kyc
,
nvl
(
sum
(
t6
.
call_num
),
0
)
as
call_num_kyc
,
nvl
(
count
(
distinct
case
when
t6_v
.
valid_call_num
>
0
then
t6_v
.
user_id
end
),
0
)
as
valid_call_dev_kyc
,
nvl
(
sum
(
t6_v
.
valid_call_num
),
0
)
as
valid_call_num_kyc
,
nvl
(
count
(
distinct
case
when
t7
.
msg_num
>
0
then
t7
.
user_id
end
),
0
)
msg_dev_qa
,
nvl
(
sum
(
t7
.
msg_num
),
0
)
msg_num_qa
,
nvl
(
count
(
distinct
case
when
t7_v
.
valid_msg_num
>
0
then
t7_v
.
user_id
end
),
0
)
valid_msg_dev_qa
,
nvl
(
sum
(
t7_v
.
valid_msg_num
),
0
)
as
valid_msg_num_qa
,
nvl
(
count
(
distinct
case
when
t8
.
clue_num
>
0
then
t8
.
user_id
end
),
0
)
as
clue_dev_qa
,
nvl
(
sum
(
t8
.
clue_num
),
0
)
as
clue_num_qa
,
nvl
(
count
(
distinct
case
when
t9
.
call_num
>
0
then
t9
.
user_id
end
),
0
)
as
call_dev_qa
,
nvl
(
sum
(
t9
.
call_num
),
0
)
as
call_num_qa
,
nvl
(
count
(
distinct
case
when
t9_v
.
valid_call_num
>
0
then
t9_v
.
user_id
end
),
0
)
as
valid_call_dev_qa
,
nvl
(
sum
(
t9_v
.
valid_call_num
),
0
)
as
valid_call_num_qa
FROM
,
count
(
distinct
case
when
t4
.
msg_num
>
0
then
t4
.
user_id
end
)
msg_dev_kyc
(
,
sum
(
t4
.
msg_num
)
msg_num_kyc
SELECT
partition_date
,
device_id
,
device_os_type
,
active_type
,
b
.
grey_type
,
count
(
distinct
case
when
t4_v
.
valid_msg_num
>
0
then
t4_v
.
user_id
end
)
valid_msg_dev_kyc
FROM
,
sum
(
t4_v
.
valid_msg_num
)
as
valid_msg_num_kyc
(
,
count
(
distinct
case
when
t5
.
clue_num
>
0
then
t5
.
user_id
end
)
as
clue_dev_kyc
SELECT
,
sum
(
t5
.
clue_num
)
as
clue_num_kyc
partition_date
,
device_id
,
device_os_type
,
case
when
active_type
in
(
'1'
,
'2'
)
then
'新增设备'
,
count
(
distinct
case
when
t7
.
msg_num
>
0
then
t7
.
user_id
end
)
msg_dev_qa
when
active_type
=
'4'
then
'老活跃设备'
end
as
active_type
,
sum
(
t7
.
msg_num
)
msg_num_qa
,
array
(
case
when
substr
(
convup
(
setencryption
(
device_id
,
'sha-1'
),
16
,
10
),
-
2
,
2
)
%
20
=
0
then
'kyc灰度'
else
'非灰'
end
,
'合计'
)
as
grey_type
,
count
(
distinct
case
when
t7_v
.
valid_msg_num
>
0
then
t7_v
.
user_id
end
)
valid_msg_dev_qa
FROM
online
.
ml_device_day_active_status
,
sum
(
t7_v
.
valid_msg_num
)
as
valid_msg_num_qa
where
partition_date
>=
REGEXP_REPLACE
(
trunc
(
date_sub
(
current_date
(),
1
),
'MM'
),
'-'
,
''
)
,
count
(
distinct
case
when
t8
.
clue_num
>
0
then
t8
.
user_id
end
)
as
clue_dev_qa
AND
partition_date
<=
regexp_replace
(
date_sub
(
current_date
,
1
),
'-'
,
''
)
,
sum
(
t8
.
clue_num
)
as
clue_num_qa
AND
active_type
in
(
'1'
,
'2'
,
'4'
)
and
device_id
is
not
null
)
a
LATERAL
VIEW
explode
(
a
.
grey_type
)
b
AS
grey_type
)
mas
left
join
(
--找出user_id当天活跃的第一个设备id
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_date
and
mas
.
device_id
=
a
.
device_id
left
join
(
--私信线索总数
SELECT
msg
.
partition_date
,
user_id
,
count
(
msg
.
merchant_id
)
as
msg_num
FROM
(
SELECT
user_id
,
merchant_id
,
SUBSTR
(
partition_day
,
1
,
6
)
AS
MONTH
,
min
(
partition_day
)
as
partition_date
FROM
ml
.
ml_c_et_msg_conversation_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
),
'-'
,
''
)
GROUP
BY
user_id
,
merchant_id
,
SUBSTR
(
partition_day
,
1
,
6
)
)
msg
GROUP
BY
msg
.
partition_date
,
user_id
)
t1
ON
a
.
partition_date
=
t1
.
partition_date
and
a
.
user_id
=
t1
.
user_id
left
join
(
--有效私信线索总数
SELECT
msg
.
partition_date
,
user_id
,
count
(
msg
.
merchant_id
)
as
valid_msg_num
FROM
(
SELECT
user_id
,
merchant_id
,
SUBSTR
(
partition_day
,
1
,
6
)
AS
MONTH
,
min
(
partition_day
)
as
partition_date
FROM
ml
.
ml_c_et_msg_conversation_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
),
'-'
,
''
)
and
is_valid
=
'true'
GROUP
BY
user_id
,
merchant_id
,
SUBSTR
(
partition_day
,
1
,
6
)
)
msg
GROUP
BY
msg
.
partition_date
,
user_id
)
t1_v
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
FROM
(
SELECT
user_id
,
merchant_id
,
MIN
(
REGEXP_REPLACE
(
SUBSTR
(
created_time
,
1
,
10
),
'-'
,
''
))
as
partition_date
,
regexp_replace
(
SUBSTR
(
created_time
,
1
,
7
),
'-'
,
''
)
AS
CALL_MONTH
FROM
tl
.
tl_gm_sl_lead_task
--线索任务表(用户点击授权后记入该表)
WHERE
partition_day
>=
REGEXP_REPLACE
(
trunc
(
date_sub
(
current_date
(),
1
),
'MM'
),
'-'
,
''
)
AND
partition_day
<=
regexp_replace
(
date_sub
(
current_date
(),
1
),
'-'
,
''
)
AND
source
=
'2'
--用户行为电话授权
GROUP
BY
user_id
,
merchant_id
,
regexp_replace
(
SUBSTR
(
created_time
,
1
,
7
),
'-'
,
''
)
)
a
GROUP
BY
partition_date
,
user_id
)
t2
ON
a
.
partition_date
=
t2
.
partition_date
and
a
.
user_id
=
t2
.
user_id
LEFT
JOIN
(
---拨打电话线索
SELECT
partition_date
,
user_id
,
count
(
1
)
as
call_num
FROM
(
SELECT
user_id
,
merchant_id
,
regexp_replace
(
SUBSTR
(
a
.
partition_date
,
1
,
6
),
'-'
,
''
)
AS
CALL_MONTH
,
MIN
(
partition_date
)
as
partition_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
(
trunc
(
date_sub
(
current_date
(),
1
),
'MM'
),
'-'
,
''
)
AND
REGEXP_REPLACE
(
SUBSTR
(
call_time
,
0
,
10
),
'-'
,
''
)
<=
regexp_replace
(
date_sub
(
current_date
(),
1
),
'-'
,
''
)
and
start_time
>
call_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'
--用户行为电话授权
)
e
ON
d
.
lead_task_id
=
e
.
id
GROUP
BY
user_id
,
merchant_id
,
regexp_replace
(
SUBSTR
(
a
.
partition_date
,
1
,
6
),
'-'
,
''
)
)
t1
GROUP
BY
user_id
,
partition_date
)
t3
ON
a
.
partition_date
=
t3
.
partition_date
and
a
.
user_id
=
t3
.
user_id
LEFT
JOIN
(
---拨打电话线索
SELECT
partition_date
,
user_id
,
count
(
1
)
as
valid_call_num
FROM
FROM
(
(
SELECT
user_id
,
merchant_id
,
regexp_replace
(
SUBSTR
(
a
.
partition_date
,
1
,
6
),
'-'
,
''
)
AS
CALL_MONTH
,
SELECT
partition_date
,
device_id
,
device_os_type
,
active_type
,
b
.
grey_type
MIN
(
partition_date
)
as
partition_date
,
1
as
call_num
FROM
FROM
(
(
SELECT
sub_id
,
REGEXP_REPLACE
(
SUBSTR
(
call_time
,
0
,
10
),
'-'
,
''
)
as
partition_date
SELECT
FROM
tl
.
tl_gm_sl_ali_virtual_phone_call_detail
--通话记录表,call_type呼叫类型
partition_date
WHERE
partition_day
=
regexp_replace
(
date_sub
(
current_date
,
1
),
'-'
,
''
)
,
device_id
,
device_os_type
AND
REGEXP_REPLACE
(
SUBSTR
(
call_time
,
0
,
10
),
'-'
,
''
)
>=
REGEXP_REPLACE
(
trunc
(
date_sub
(
current_date
(),
1
),
'MM'
),
'-'
,
''
)
,
case
when
active_type
in
(
'1'
,
'2'
)
then
'新增设备'
AND
REGEXP_REPLACE
(
SUBSTR
(
call_time
,
0
,
10
),
'-'
,
''
)
<=
regexp_replace
(
date_sub
(
current_date
(),
1
),
'-'
,
''
)
when
active_type
=
'4'
then
'老活跃设备'
end
as
active_type
and
start_time
>
call_time
,
array
(
case
when
substr
(
convup
(
setencryption
(
device_id
,
'sha-1'
),
16
,
10
),
-
2
,
2
)
%
20
=
0
then
'kyc灰度'
else
'非灰'
end
,
'合计'
)
as
grey_type
and
unix_timestamp
(
substr
(
start_time
,
1
,
19
))
+
30
<=
unix_timestamp
(
substr
(
release_time
,
1
,
19
))
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'
)
and
device_id
is
not
null
)
a
)
a
LEFT
JOIN
LATERAL
VIEW
explode
(
a
.
grey_type
)
b
AS
grey_type
(
)
mas
SELECT
id
,
sub_id
left
join
FROM
tl
.
tl_gm_sl_ali_virtual_phone_binding
--阿里记录表
(
--找出user_id当天活跃的第一个设备id
WHERE
partition_day
=
regexp_replace
(
date_sub
(
current_date
,
1
),
'-'
,
''
)
SELECT
user_id
,
partition_day
,
)
b
if
(
size
(
device_id_list
)
>
0
,
device_id_list
[
0
],
''
)
AS
device_id
ON
a
.
sub_id
=
b
.
sub_id
FROM
ml
.
ml_c_ct_ui_user_dimen_inc_d
LEFT
JOIN
WHERE
partition_day
>=
REGEXP_REPLACE
(
trunc
(
date_sub
(
current_date
(),
1
),
'MM'
),
'-'
,
''
)
(
AND
partition_day
<=
regexp_replace
(
date_sub
(
current_date
,
1
),
'-'
,
''
)
SELECT
id
,
platform_binding_id
)
a
FROM
tl
.
tl_gm_sl_virtual_phone_binding
on
mas
.
partition_date
=
a
.
partition_day
and
mas
.
device_id
=
a
.
device_id
WHERE
partition_day
=
regexp_replace
(
date_sub
(
current_date
,
1
),
'-'
,
''
)
left
join
)
c
(
--私信线索总数
ON
b
.
id
=
c
.
platform_binding_id
SELECT
msg
.
partition_date
,
user_id
LEFT
JOIN
,
count
(
msg
.
merchant_id
)
as
msg_num
(
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'
--用户行为电话授权
)
e
ON
d
.
lead_task_id
=
e
.
id
GROUP
BY
user_id
,
merchant_id
,
regexp_replace
(
SUBSTR
(
a
.
partition_date
,
1
,
6
),
'-'
,
''
)
)
t1
GROUP
BY
user_id
,
partition_date
)
t3_v
ON
a
.
partition_date
=
t3_v
.
partition_date
and
a
.
user_id
=
t3_v
.
user_id
left
join
(
--kyc私信
SELECT
msg
.
partition_date
,
user_id
,
count
(
msg
.
merchant_id
)
as
msg_num
FROM
(
SELECT
user_id
,
merchant_id
,
SUBSTR
(
partition_day
,
1
,
6
)
AS
MONTH
,
min
(
partition_day
)
as
partition_date
FROM
FROM
(
(
SELECT
distinct
conversation_id
SELECT
user_id
,
merchant_id
,
SUBSTR
(
partition_day
,
1
,
6
)
AS
MONTH
,
min
(
partition_day
)
as
partition_date
FROM
online
.
tl_hdfs_message_view
WHERE
partition_date
=
regexp_replace
(
DATE_SUB
(
current_date
,
1
)
,
'-'
,
''
)
and
regexp_replace
(
to_date
(
send_time
)
,
'-'
,
''
)
>=
REGEXP_REPLACE
(
trunc
(
date_sub
(
current_date
(),
1
),
'MM'
),
'-'
,
''
)
and
regexp_replace
(
to_date
(
send_time
)
,
'-'
,
''
)
<=
regexp_replace
(
date_sub
(
current_date
,
1
),
'-'
,
''
)
and
content
like
'%对%感兴趣'
)
a
join
(
SELECT
user_id
,
merchant_id
,
conversation_id
,
partition_day
FROM
ml
.
ml_c_et_msg_conversation_dimen_inc_d
--新仓库私信表
FROM
ml
.
ml_c_et_msg_conversation_dimen_inc_d
--新仓库私信表
WHERE
partition_day
>=
REGEXP_REPLACE
(
trunc
(
date_sub
(
current_date
(),
1
),
'MM'
),
'-'
,
''
)
WHERE
partition_day
>=
REGEXP_REPLACE
(
trunc
(
date_sub
(
current_date
(),
1
),
'MM'
),
'-'
,
''
)
AND
partition_day
<=
regexp_replace
(
date_sub
(
current_date
,
1
),
'-'
,
''
)
AND
partition_day
<=
regexp_replace
(
date_sub
(
current_date
,
1
),
'-'
,
''
)
GROUP
BY
user_id
,
merchant_id
,
conversation_id
,
partition_day
GROUP
BY
user_id
,
merchant_id
,
SUBSTR
(
partition_day
,
1
,
6
)
)
b
)
msg
on
a
.
conversation_id
=
b
.
conversation_id
GROUP
BY
msg
.
partition_date
,
user_id
group
by
user_id
,
merchant_id
,
SUBSTR
(
partition_day
,
1
,
6
)
)
t1
)
msg
ON
a
.
partition_day
=
t1
.
partition_date
and
a
.
user_id
=
t1
.
user_id
group
by
msg
.
partition_date
,
user_id
left
join
)
t4
(
--有效私信线索总数
on
a
.
partition_date
=
t4
.
partition_date
and
a
.
user_id
=
t4
.
user_id
SELECT
msg
.
partition_date
,
user_id
left
join
,
count
(
msg
.
merchant_id
)
as
valid_msg_num
(
--kyc私信
SELECT
msg
.
partition_date
,
user_id
,
count
(
msg
.
merchant_id
)
as
valid_msg_num
FROM
(
SELECT
user_id
,
merchant_id
,
SUBSTR
(
partition_day
,
1
,
6
)
AS
MONTH
,
min
(
partition_day
)
as
partition_date
FROM
FROM
(
(
SELECT
distinct
conversation_id
SELECT
user_id
,
merchant_id
,
SUBSTR
(
partition_day
,
1
,
6
)
AS
MONTH
,
min
(
partition_day
)
as
partition_date
FROM
online
.
tl_hdfs_message_view
WHERE
partition_date
=
regexp_replace
(
DATE_SUB
(
current_date
,
1
)
,
'-'
,
''
)
and
regexp_replace
(
to_date
(
send_time
)
,
'-'
,
''
)
>=
REGEXP_REPLACE
(
trunc
(
date_sub
(
current_date
(),
1
),
'MM'
),
'-'
,
''
)
and
regexp_replace
(
to_date
(
send_time
)
,
'-'
,
''
)
<=
regexp_replace
(
date_sub
(
current_date
,
1
),
'-'
,
''
)
and
content
like
'%对%感兴趣'
)
a
join
(
SELECT
user_id
,
merchant_id
,
conversation_id
,
partition_day
FROM
ml
.
ml_c_et_msg_conversation_dimen_inc_d
--新仓库私信表
FROM
ml
.
ml_c_et_msg_conversation_dimen_inc_d
--新仓库私信表
WHERE
partition_day
>=
REGEXP_REPLACE
(
trunc
(
date_sub
(
current_date
(),
1
),
'MM'
),
'-'
,
''
)
WHERE
partition_day
>=
REGEXP_REPLACE
(
trunc
(
date_sub
(
current_date
(),
1
),
'MM'
),
'-'
,
''
)
AND
partition_day
<=
regexp_replace
(
date_sub
(
current_date
,
1
),
'-'
,
''
)
AND
partition_day
<=
regexp_replace
(
date_sub
(
current_date
,
1
),
'-'
,
''
)
and
is_valid
=
'true'
and
is_valid
=
'true'
GROUP
BY
user_id
,
merchant_id
,
conversation_id
,
partition_day
GROUP
BY
user_id
,
merchant_id
,
SUBSTR
(
partition_day
,
1
,
6
)
)
b
)
msg
on
a
.
conversation_id
=
b
.
conversation_id
GROUP
BY
msg
.
partition_date
,
user_id
group
by
user_id
,
merchant_id
,
SUBSTR
(
partition_day
,
1
,
6
)
)
t1_v
)
msg
ON
a
.
partition_day
=
t1_v
.
partition_date
and
a
.
user_id
=
t1_v
.
user_id
group
by
msg
.
partition_date
,
user_id
LEFT
JOIN
)
t4_v
(
--电话线索总数
on
a
.
partition_date
=
t4_v
.
partition_date
and
a
.
user_id
=
t4_v
.
user_id
SELECT
partition_date
,
user_id
,
count
(
1
)
AS
clue_num
LEFT
JOIN
(
--kyc电话线索总数
SELECT
partition_date
,
user_id
,
count
(
1
)
as
clue_num
FROM
(
SELECT
a
.
user_id
,
a
.
merchant_id
,
substr
(
a
.
partition_date
,
1
,
6
)
as
month
,
min
(
a
.
partition_date
)
as
partition_date
FROM
FROM
(
(
SELECT
user_id
,
merchant_id
,
REGEXP_REPLACE
(
SUBSTR
(
created_time
,
1
,
10
),
'-'
,
''
)
as
partition_date
SELECT
user_id
,
merchant_id
,
MIN
(
REGEXP_REPLACE
(
SUBSTR
(
created_time
,
1
,
10
),
'-'
,
''
))
as
partition_date
,
regexp_replace
(
SUBSTR
(
created_time
,
1
,
7
),
'-'
,
''
)
AS
CALL_MONTH
FROM
tl
.
tl_gm_sl_lead_task
--线索任务表(用户点击授权后记入该表)
FROM
tl
.
tl_gm_sl_lead_task
--线索任务表(用户点击授权后记入该表)
WHERE
partition_day
>=
REGEXP_REPLACE
(
trunc
(
date_sub
(
current_date
(),
1
),
'MM'
),
'-'
,
''
)
WHERE
partition_day
>=
REGEXP_REPLACE
(
trunc
(
date_sub
(
current_date
(),
1
),
'MM'
),
'-'
,
''
)
AND
partition_day
<=
regexp_replace
(
date_sub
(
current_date
(),
1
),
'-'
,
''
)
AND
partition_day
<=
regexp_replace
(
date_sub
(
current_date
(),
1
),
'-'
,
''
)
AND
source
=
'2'
--用户行为电话授权
AND
source
=
'2'
--用户行为电话授权
GROUP
BY
user_id
,
merchant_id
,
regexp_replace
(
SUBSTR
(
created_time
,
1
,
10
),
'-'
,
''
)
GROUP
BY
user_id
,
merchant_id
,
regexp_replace
(
SUBSTR
(
created_time
,
1
,
7
),
'-'
,
''
)
)
a
)
a
join
GROUP
BY
partition_date
,
user_id
)
t2
ON
a
.
partition_day
=
t2
.
partition_date
and
a
.
user_id
=
t2
.
user_id
left
join
(
--kyc私信
SELECT
msg
.
partition_date
,
user_id
,
count
(
msg
.
merchant_id
)
as
msg_num
FROM
(
(
SELECT
partition_date
,
user_id
,
merchant_id
SELECT
user_id
,
merchant_id
,
SUBSTR
(
partition_day
,
1
,
6
)
AS
MONTH
,
min
(
partition_day
)
as
partition_date
from
FROM
(
(
SELECT
partition_date
,
cl_id
,
user_id
,
hospital_id
SELECT
distinct
conversation_id
from
FROM
online
.
tl_hdfs_message_view
(
WHERE
partition_date
=
regexp_replace
(
DATE_SUB
(
current_date
,
1
)
,
'-'
,
''
)
SELECT
partition_date
,
cl_id
,
user_id
,
json_split
(
params
[
'hospital_id'
],
'string'
)
as
hospital_ids
and
regexp_replace
(
to_date
(
send_time
)
,
'-'
,
''
)
>=
REGEXP_REPLACE
(
trunc
(
date_sub
(
current_date
(),
1
),
'MM'
),
'-'
,
''
)
FROM
online
.
bl_hdfs_maidian_updates
and
regexp_replace
(
to_date
(
send_time
)
,
'-'
,
''
)
<=
regexp_replace
(
date_sub
(
current_date
,
1
),
'-'
,
''
)
where
partition_date
>=
REGEXP_REPLACE
(
trunc
(
date_sub
(
current_date
(),
1
),
'MM'
),
'-'
,
''
)
and
content
like
'%对%感兴趣'
AND
partition_date
<=
regexp_replace
(
date_sub
(
current_date
,
1
),
'-'
,
''
)
)
a
and
page_name
in
(
'kyc_phone'
)
join
and
action
=
'on_click_button'
(
and
params
[
'button_name'
]
=
'agree'
SELECT
user_id
,
merchant_id
,
conversation_id
,
partition_day
and
params
[
'hospital_id'
]
like
'%[%'
--其实传的是doctor_id
FROM
ml
.
ml_c_et_msg_conversation_dimen_inc_d
--新仓库私信表
)
a
WHERE
partition_day
>=
REGEXP_REPLACE
(
trunc
(
date_sub
(
current_date
(),
1
),
'MM'
),
'-'
,
''
)
LATERAL
VIEW
explode
(
hospital_ids
)
b
AS
hospital_id
AND
partition_day
<=
regexp_replace
(
date_sub
(
current_date
,
1
),
'-'
,
''
)
group
by
partition_date
,
cl_id
,
user_id
,
hospital_id
GROUP
BY
user_id
,
merchant_id
,
conversation_id
,
partition_day
)
a
)
b
join
on
a
.
conversation_id
=
b
.
conversation_id
(
group
by
user_id
,
merchant_id
,
SUBSTR
(
partition_day
,
1
,
6
)
SELECT
doctor_id
,
merchant_id
)
msg
FROM
online
.
ml_doctor_relation_dimen_day
group
by
msg
.
partition_date
,
user_id
WHERE
partition_date
=
regexp_replace
(
date_sub
(
current_date
,
1
),
'-'
,
''
)
)
t4
AND
doctor_is_merchant
=
'true'
--医生是商户
on
a
.
partition_day
=
t4
.
partition_date
and
a
.
user_id
=
t4
.
user_id
GROUP
BY
doctor_id
,
merchant_id
left
join
)
b
(
--kyc有效私信
on
a
.
hospital_id
=
b
.
doctor_id
SELECT
msg
.
partition_date
,
user_id
)
kyc
,
count
(
msg
.
merchant_id
)
as
valid_msg_num
on
a
.
user_id
=
kyc
.
user_id
and
a
.
merchant_id
=
kyc
.
merchant_id
and
a
.
partition_date
=
kyc
.
partition_date
GROUP
BY
a
.
user_id
,
a
.
merchant_id
,
substr
(
a
.
partition_date
,
1
,
6
)
)
a
group
by
partition_date
,
user_id
)
t5
ON
a
.
partition_date
=
t5
.
partition_date
and
a
.
user_id
=
t5
.
user_id
LEFT
JOIN
(
---拨打电话线索
SELECT
partition_date
,
user_id
,
count
(
1
)
as
call_num
FROM
(
SELECT
e
.
user_id
,
e
.
merchant_id
,
regexp_replace
(
SUBSTR
(
a
.
partition_date
,
1
,
6
),
'-'
,
''
)
AS
CALL_MONTH
,
MIN
(
a
.
partition_date
)
as
partition_date
,
1
as
call_num
FROM
FROM
(
(
SELECT
sub_id
,
REGEXP_REPLACE
(
SUBSTR
(
call_time
,
0
,
10
),
'-'
,
''
)
as
partition_date
SELECT
user_id
,
merchant_id
,
SUBSTR
(
partition_day
,
1
,
6
)
AS
MONTH
,
min
(
partition_day
)
as
partition_date
FROM
tl
.
tl_gm_sl_ali_virtual_phone_call_detail
--通话记录表,call_type呼叫类型
FROM
WHERE
partition_day
=
regexp_replace
(
date_sub
(
current_date
,
1
),
'-'
,
''
)
(
AND
REGEXP_REPLACE
(
SUBSTR
(
call_time
,
0
,
10
),
'-'
,
''
)
>=
REGEXP_REPLACE
(
trunc
(
date_sub
(
current_date
(),
1
),
'MM'
),
'-'
,
''
)
SELECT
distinct
conversation_id
AND
REGEXP_REPLACE
(
SUBSTR
(
call_time
,
0
,
10
),
'-'
,
''
)
<=
regexp_replace
(
date_sub
(
current_date
(),
1
),
'-'
,
''
)
FROM
online
.
tl_hdfs_message_view
and
start_time
>
call_time
WHERE
partition_date
=
regexp_replace
(
DATE_SUB
(
current_date
,
1
)
,
'-'
,
''
)
)
a
and
regexp_replace
(
to_date
(
send_time
)
,
'-'
,
''
)
>=
REGEXP_REPLACE
(
trunc
(
date_sub
(
current_date
(),
1
),
'MM'
),
'-'
,
''
)
LEFT
JOIN
and
regexp_replace
(
to_date
(
send_time
)
,
'-'
,
''
)
<=
regexp_replace
(
date_sub
(
current_date
,
1
),
'-'
,
''
)
(
and
content
like
'%对%感兴趣'
SELECT
id
,
sub_id
)
a
FROM
tl
.
tl_gm_sl_ali_virtual_phone_binding
--阿里记录表
join
WHERE
partition_day
=
regexp_replace
(
date_sub
(
current_date
,
1
),
'-'
,
''
)
(
)
b
SELECT
user_id
,
merchant_id
,
conversation_id
,
partition_day
ON
a
.
sub_id
=
b
.
sub_id
FROM
ml
.
ml_c_et_msg_conversation_dimen_inc_d
--新仓库私信表
LEFT
JOIN
WHERE
partition_day
>=
REGEXP_REPLACE
(
trunc
(
date_sub
(
current_date
(),
1
),
'MM'
),
'-'
,
''
)
(
AND
partition_day
<=
regexp_replace
(
date_sub
(
current_date
,
1
),
'-'
,
''
)
SELECT
id
,
platform_binding_id
and
is_valid
=
'true'
FROM
tl
.
tl_gm_sl_virtual_phone_binding
GROUP
BY
user_id
,
merchant_id
,
conversation_id
,
partition_day
WHERE
partition_day
=
regexp_replace
(
date_sub
(
current_date
,
1
),
'-'
,
''
)
)
b
)
c
on
a
.
conversation_id
=
b
.
conversation_id
ON
b
.
id
=
c
.
platform_binding_id
group
by
user_id
,
merchant_id
,
SUBSTR
(
partition_day
,
1
,
6
)
LEFT
JOIN
)
msg
(
group
by
msg
.
partition_date
,
user_id
SELECT
phone_binding_id
,
lead_task_id
)
t4_v
FROM
tl
.
tl_gm_sl_lead_task_phone_binding
on
a
.
partition_day
=
t4_v
.
partition_date
and
a
.
user_id
=
t4_v
.
user_id
WHERE
partition_day
=
regexp_replace
(
date_sub
(
current_date
,
1
),
'-'
,
''
)
LEFT
JOIN
)
d
(
--kyc电话线索总数
ON
c
.
id
=
d
.
phone_binding_id
SELECT
partition_date
,
user_id
,
count
(
1
)
as
clue_num
JOIN
FROM
(
SELECT
id
,
user_id
,
merchant_id
,
REGEXP_REPLACE
(
SUBSTR
(
created_time
,
1
,
10
),
'-'
,
''
)
as
partition_date
FROM
tl
.
tl_gm_sl_lead_task
--线索任务表(用户点击授权后记入该表)
WHERE
partition_day
>=
REGEXP_REPLACE
(
trunc
(
date_sub
(
current_date
(),
1
),
'MM'
),
'-'
,
''
)
AND
partition_day
<=
regexp_replace
(
date_sub
(
current_date
(),
1
),
'-'
,
''
)
AND
source
=
'2'
--用户行为电话授权
group
by
id
,
user_id
,
merchant_id
,
created_time
)
e
ON
d
.
lead_task_id
=
e
.
id
join
(
(
SELECT
partition_date
,
user_id
,
merchant_id
SELECT
a
.
user_id
,
a
.
merchant_id
,
substr
(
a
.
partition_date
,
1
,
6
)
as
month
,
min
(
a
.
partition_date
)
as
partition_date
from
FROM
(
SELECT
user_id
,
merchant_id
,
REGEXP_REPLACE
(
SUBSTR
(
created_time
,
1
,
10
),
'-'
,
''
)
as
partition_date
FROM
tl
.
tl_gm_sl_lead_task
--线索任务表(用户点击授权后记入该表)
WHERE
partition_day
>=
REGEXP_REPLACE
(
trunc
(
date_sub
(
current_date
(),
1
),
'MM'
),
'-'
,
''
)
AND
partition_day
<=
regexp_replace
(
date_sub
(
current_date
(),
1
),
'-'
,
''
)
AND
source
=
'2'
--用户行为电话授权
GROUP
BY
user_id
,
merchant_id
,
regexp_replace
(
SUBSTR
(
created_time
,
1
,
10
),
'-'
,
''
)
)
a
join
(
(
SELECT
partition_date
,
cl_id
,
user_id
,
hospital
_id
SELECT
partition_date
,
user_id
,
merchant
_id
from
from
(
(
SELECT
partition_date
,
cl_id
,
user_id
,
json_split
(
params
[
'hospital_id'
],
'string'
)
as
hospital_ids
SELECT
partition_date
,
cl_id
,
user_id
,
hospital_id
FROM
online
.
bl_hdfs_maidian_updates
from
where
partition_date
>=
REGEXP_REPLACE
(
trunc
(
date_sub
(
current_date
(),
1
),
'MM'
),
'-'
,
''
)
(
AND
partition_date
<=
regexp_replace
(
date_sub
(
current_date
,
1
),
'-'
,
''
)
SELECT
partition_date
,
cl_id
,
user_id
,
json_split
(
params
[
'hospital_id'
],
'string'
)
as
hospital_ids
and
page_name
in
(
'kyc_phone'
)
FROM
online
.
bl_hdfs_maidian_updates
and
action
=
'on_click_button'
where
partition_date
>=
REGEXP_REPLACE
(
trunc
(
date_sub
(
current_date
(),
1
),
'MM'
),
'-'
,
''
)
and
params
[
'button_name'
]
=
'agree'
AND
partition_date
<=
regexp_replace
(
date_sub
(
current_date
,
1
),
'-'
,
''
)
and
params
[
'hospital_id'
]
like
'%[%'
--其实传的是doctor_id
and
page_name
in
(
'kyc_phone'
)
)
a
and
action
=
'on_click_button'
LATERAL
VIEW
explode
(
hospital_ids
)
b
AS
hospital_id
and
params
[
'button_name'
]
=
'agree'
group
by
partition_date
,
cl_id
,
user_id
,
hospital_id
and
params
[
'hospital_id'
]
like
'%[%'
--其实传的是doctor_id
)
a
)
a
join
LATERAL
VIEW
explode
(
hospital_ids
)
b
AS
hospital_id
(
group
by
partition_date
,
cl_id
,
user_id
,
hospital_id
SELECT
doctor_id
,
merchant_id
)
a
FROM
online
.
ml_doctor_relation_dimen_day
join
WHERE
partition_date
=
regexp_replace
(
date_sub
(
current_date
,
1
),
'-'
,
''
)
(
AND
doctor_is_merchant
=
'true'
--医生是商户
SELECT
doctor_id
,
merchant_id
GROUP
BY
doctor_id
,
merchant_id
FROM
online
.
ml_doctor_relation_dimen_day
)
b
WHERE
partition_date
=
regexp_replace
(
date_sub
(
current_date
,
1
),
'-'
,
''
)
on
a
.
hospital_id
=
b
.
doctor_id
AND
doctor_is_merchant
=
'true'
--医生是商户
)
kyc
GROUP
BY
doctor_id
,
merchant_id
on
e
.
user_id
=
kyc
.
user_id
and
e
.
merchant_id
=
kyc
.
merchant_id
and
e
.
partition_date
=
kyc
.
partition_date
)
b
GROUP
BY
e
.
user_id
,
e
.
merchant_id
,
regexp_replace
(
SUBSTR
(
a
.
partition_date
,
1
,
6
),
'-'
,
''
)
on
a
.
hospital_id
=
b
.
doctor_id
)
t1
)
kyc
GROUP
BY
user_id
,
partition_date
on
a
.
user_id
=
kyc
.
user_id
and
a
.
merchant_id
=
kyc
.
merchant_id
and
a
.
partition_date
=
kyc
.
partition_date
)
t6
GROUP
BY
a
.
user_id
,
a
.
merchant_id
,
substr
(
a
.
partition_date
,
1
,
6
)
ON
a
.
partition_date
=
t6
.
partition_date
and
a
.
user_id
=
t6
.
user_id
LEFT
JOIN
(
---拨打电话线索
SELECT
partition_date
,
user_id
,
count
(
1
)
as
valid_call_num
FROM
(
SELECT
e
.
user_id
,
e
.
merchant_id
,
regexp_replace
(
SUBSTR
(
a
.
partition_date
,
1
,
6
),
'-'
,
''
)
AS
CALL_MONTH
,
MIN
(
a
.
partition_date
)
as
partition_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
(
trunc
(
date_sub
(
current_date
(),
1
),
'MM'
),
'-'
,
''
)
AND
REGEXP_REPLACE
(
SUBSTR
(
call_time
,
0
,
10
),
'-'
,
''
)
<=
regexp_replace
(
date_sub
(
current_date
(),
1
),
'-'
,
''
)
and
start_time
>
call_time
and
unix_timestamp
(
substr
(
start_time
,
1
,
19
))
+
30
<=
unix_timestamp
(
substr
(
release_time
,
1
,
19
))
)
a
)
a
LEFT
JOIN
group
by
partition_date
,
user_id
(
)
t5
SELECT
id
,
sub_id
ON
a
.
partition_day
=
t5
.
partition_date
and
a
.
user_id
=
t5
.
user_id
FROM
tl
.
tl_gm_sl_ali_virtual_phone_binding
--阿里记录表
WHERE
partition_day
=
regexp_replace
(
date_sub
(
current_date
,
1
),
'-'
,
''
)
left
join
)
b
(
--需求自测私信
ON
a
.
sub_id
=
b
.
sub_id
SELECT
msg
.
partition_date
,
user_id
LEFT
JOIN
,
count
(
msg
.
merchant_id
)
as
msg_num
(
FROM
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
,
REGEXP_REPLACE
(
SUBSTR
(
created_time
,
1
,
10
),
'-'
,
''
)
as
partition_date
FROM
tl
.
tl_gm_sl_lead_task
--线索任务表(用户点击授权后记入该表)
WHERE
partition_day
>=
REGEXP_REPLACE
(
trunc
(
date_sub
(
current_date
(),
1
),
'MM'
),
'-'
,
''
)
AND
partition_day
<=
regexp_replace
(
date_sub
(
current_date
(),
1
),
'-'
,
''
)
AND
source
=
'2'
--用户行为电话授权
group
by
id
,
user_id
,
merchant_id
,
created_time
)
e
ON
d
.
lead_task_id
=
e
.
id
join
(
(
SELECT
partition_date
,
user_id
,
merchant_id
SELECT
a
.
user_id
,
a
.
merchant_id
,
substr
(
partition_day
,
1
,
6
)
as
month
,
min
(
partition_day
)
as
partition_date
from
FROM
(
(
SELECT
partition_date
,
cl_id
,
user_id
,
hospital
_id
SELECT
partition_date
,
user_id
,
merchant
_id
from
from
(
--点击发送
SELECT
a
.
partition_date
,
user_id
,
cl_id
,
json_map
(
b
.
hospital_id
,
'string,string'
)[
'hospital_id'
]
hospital_id
FROM
(
SELECT
partition_date
,
user_id
,
cl_id
,
json_split
(
params
[
'hospital_id_list'
])
as
hospital_id_list
FROM
online
.
bl_hdfs_maidian_updates
where
partition_date
>=
REGEXP_REPLACE
(
trunc
(
date_sub
(
current_date
(),
1
),
'MM'
),
'-'
,
''
)
AND
partition_date
<=
regexp_replace
(
date_sub
(
current_date
,
1
),
'-'
,
''
)
and
page_name
=
'ai_plan_consult_list'
and
params
[
'button_name'
]
in
(
'send'
)
and
action
=
'on_click_button'
and
int
(
split
(
app_version
,
'
\\
.'
)[
1
])
>=
31
group
by
partition_date
,
user_id
,
cl_id
,
params
[
'hospital_id_list'
]
)
a
LATERAL
VIEW
EXPLODE
(
a
.
hospital_id_list
)
b
as
hospital_id
)
b
join
(
(
SELECT
partition_date
,
cl_id
,
user_id
,
json_split
(
params
[
'hospital_id'
],
'string'
)
as
hospital_ids
SELECT
hospital_id
,
merchant_id
FROM
online
.
bl_hdfs_maidian_updates
FROM
online
.
ml_doctor_relation_dimen_day
where
partition_date
>=
REGEXP_REPLACE
(
trunc
(
date_sub
(
current_date
(),
1
),
'MM'
),
'-'
,
''
)
WHERE
partition_date
=
regexp_replace
(
date_sub
(
current_date
,
1
),
'-'
,
''
)
AND
partition_date
<=
regexp_replace
(
date_sub
(
current_date
,
1
),
'-'
,
''
)
AND
doctor_is_merchant
=
'true'
--医生是商户
and
page_name
in
(
'kyc_phone'
)
GROUP
BY
hospital_id
,
merchant_id
and
action
=
'on_click_button'
)
c
and
params
[
'button_name'
]
=
'agree'
on
c
.
hospital_id
=
b
.
hospital_id
and
params
[
'hospital_id'
]
like
'%[%'
--其实传的是doctor_id
group
by
partition_date
,
user_id
,
merchant_id
)
a
)
a
LATERAL
VIEW
explode
(
hospital_ids
)
b
AS
hospital_id
join
group
by
partition_date
,
cl_id
,
user_id
,
hospital_id
(
)
a
SELECT
user_id
,
merchant_id
,
partition_day
join
FROM
ml
.
ml_c_et_msg_conversation_dimen_inc_d
--新仓库私信表
(
WHERE
partition_day
>=
REGEXP_REPLACE
(
trunc
(
date_sub
(
current_date
(),
1
),
'MM'
),
'-'
,
''
)
SELECT
doctor_id
,
merchant_id
AND
partition_day
<=
regexp_replace
(
date_sub
(
current_date
,
1
),
'-'
,
''
)
FROM
online
.
ml_doctor_relation_dimen_day
GROUP
BY
user_id
,
merchant_id
,
partition_day
WHERE
partition_date
=
regexp_replace
(
date_sub
(
current_date
,
1
),
'-'
,
''
)
)
b
AND
doctor_is_merchant
=
'true'
--医生是商户
on
a
.
user_id
=
b
.
user_id
and
a
.
merchant_id
=
b
.
merchant_id
and
a
.
partition_date
=
b
.
partition_day
GROUP
BY
doctor_id
,
merchant_id
group
by
a
.
user_id
,
a
.
merchant_id
,
substr
(
partition_day
,
1
,
6
)
)
b
)
msg
on
a
.
hospital_id
=
b
.
doctor_id
group
by
msg
.
partition_date
,
user_id
)
kyc
)
t7
on
e
.
user_id
=
kyc
.
user_id
and
e
.
merchant_id
=
kyc
.
merchant_id
and
e
.
partition_date
=
kyc
.
partition_date
on
a
.
partition_day
=
t7
.
partition_date
and
a
.
user_id
=
t7
.
user_id
GROUP
BY
e
.
user_id
,
e
.
merchant_id
,
regexp_replace
(
SUBSTR
(
a
.
partition_date
,
1
,
6
),
'-'
,
''
)
left
join
)
t1
(
--需求自测有效私信
GROUP
BY
user_id
,
partition_date
SELECT
msg
.
partition_date
,
user_id
)
t6_v
,
count
(
msg
.
merchant_id
)
as
valid_msg_num
ON
a
.
partition_date
=
t6_v
.
partition_date
and
a
.
user_id
=
t6_v
.
user_id
left
join
(
--需求自测私信
SELECT
msg
.
partition_date
,
user_id
,
count
(
msg
.
merchant_id
)
as
msg_num
FROM
(
SELECT
a
.
user_id
,
a
.
merchant_id
,
substr
(
partition_day
,
1
,
6
)
as
month
,
min
(
partition_day
)
as
partition_date
FROM
FROM
(
(
SELECT
partition_date
,
user_id
,
merchant_id
SELECT
a
.
user_id
,
a
.
merchant_id
,
substr
(
partition_day
,
1
,
6
)
as
month
,
min
(
partition_day
)
as
partition_date
from
FROM
(
--点击发送
(
SELECT
a
.
partition_date
,
user_id
,
cl_id
SELECT
partition_date
,
user_id
,
merchant_id
,
json_map
(
b
.
hospital_id
,
'string,string'
)[
'hospital_id'
]
hospital_id
from
FROM
(
--点击发送
SELECT
a
.
partition_date
,
user_id
,
cl_id
,
json_map
(
b
.
hospital_id
,
'string,string'
)[
'hospital_id'
]
hospital_id
FROM
(
SELECT
partition_date
,
user_id
,
cl_id
,
json_split
(
params
[
'hospital_id_list'
])
as
hospital_id_list
FROM
online
.
bl_hdfs_maidian_updates
where
partition_date
>=
REGEXP_REPLACE
(
trunc
(
date_sub
(
current_date
(),
1
),
'MM'
),
'-'
,
''
)
AND
partition_date
<=
regexp_replace
(
date_sub
(
current_date
,
1
),
'-'
,
''
)
and
page_name
=
'ai_plan_consult_list'
and
params
[
'button_name'
]
in
(
'send'
)
and
action
=
'on_click_button'
and
int
(
split
(
app_version
,
'
\\
.'
)[
1
])
>=
31
group
by
partition_date
,
user_id
,
cl_id
,
params
[
'hospital_id_list'
]
)
a
LATERAL
VIEW
EXPLODE
(
a
.
hospital_id_list
)
b
as
hospital_id
)
b
join
(
(
SELECT
partition_date
,
user_id
,
cl_id
,
json_split
(
params
[
'hospital_id_list'
])
as
hospital_id_list
SELECT
hospital_id
,
merchant_id
FROM
online
.
bl_hdfs_maidian_updates
FROM
online
.
ml_doctor_relation_dimen_day
where
partition_date
>=
REGEXP_REPLACE
(
trunc
(
date_sub
(
current_date
(),
1
),
'MM'
),
'-'
,
''
)
WHERE
partition_date
=
regexp_replace
(
date_sub
(
current_date
,
1
),
'-'
,
''
)
AND
partition_date
<=
regexp_replace
(
date_sub
(
current_date
,
1
),
'-'
,
''
)
AND
doctor_is_merchant
=
'true'
--医生是商户
and
page_name
=
'ai_plan_consult_list'
GROUP
BY
hospital_id
,
merchant_id
and
params
[
'button_name'
]
in
(
'send'
)
)
c
and
action
=
'on_click_button'
on
c
.
hospital_id
=
b
.
hospital_id
and
int
(
split
(
app_version
,
'
\\
.'
)[
1
])
>=
31
group
by
partition_date
,
user_id
,
merchant_id
group
by
partition_date
,
user_id
,
cl_id
,
params
[
'hospital_id_list'
]
)
a
)
a
join
LATERAL
VIEW
EXPLODE
(
a
.
hospital_id_list
)
b
as
hospital_id
(
SELECT
user_id
,
merchant_id
,
partition_day
FROM
ml
.
ml_c_et_msg_conversation_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
),
'-'
,
''
)
and
is_valid
=
'true'
GROUP
BY
user_id
,
merchant_id
,
partition_day
)
b
)
b
on
a
.
user_id
=
b
.
user_id
and
a
.
merchant_id
=
b
.
merchant_id
and
a
.
partition_date
=
b
.
partition_day
group
by
a
.
user_id
,
a
.
merchant_id
,
substr
(
partition_day
,
1
,
6
)
)
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
LEFT
JOIN
(
--需求自测电话线索总数
SELECT
partition_date
,
user_id
,
count
(
1
)
as
clue_num
FROM
(
SELECT
a
.
user_id
,
a
.
merchant_id
,
substr
(
a
.
partition_date
,
1
,
6
)
as
month
,
min
(
a
.
partition_date
)
as
partition_date
FROM
(
SELECT
user_id
,
merchant_id
,
REGEXP_REPLACE
(
SUBSTR
(
created_time
,
1
,
10
),
'-'
,
''
)
as
partition_date
FROM
tl
.
tl_gm_sl_lead_task
--线索任务表(用户点击授权后记入该表)
WHERE
partition_day
>=
REGEXP_REPLACE
(
trunc
(
date_sub
(
current_date
(),
1
),
'MM'
),
'-'
,
''
)
AND
partition_day
<=
regexp_replace
(
date_sub
(
current_date
(),
1
),
'-'
,
''
)
AND
source
=
'2'
--用户行为电话授权
GROUP
BY
user_id
,
merchant_id
,
regexp_replace
(
SUBSTR
(
created_time
,
1
,
10
),
'-'
,
''
)
)
a
join
join
(
(
SELECT
hospital_id
,
merchant_id
SELECT
partition_date
,
cl_id
,
user_id
FROM
online
.
ml_doctor_relation_dimen_day
FROM
online
.
bl_hdfs_maidian_updates
WHERE
partition_date
=
regexp_replace
(
date_sub
(
current_date
,
1
),
'-'
,
''
)
where
partition_date
>=
REGEXP_REPLACE
(
trunc
(
date_sub
(
current_date
(),
1
),
'MM'
),
'-'
,
''
)
AND
doctor_is_merchant
=
'true'
--医生是商户
AND
partition_date
<=
regexp_replace
(
date_sub
(
current_date
,
1
),
'-'
,
''
)
GROUP
BY
hospital_id
,
merchant_id
and
params
[
'popup_name'
]
=
'bargain_phone'
)
c
and
page_name
=
'ai_plan_list'
on
c
.
hospital_id
=
b
.
hospital_id
and
params
[
'button_name'
]
in
(
'confirm'
)
group
by
partition_date
,
user_id
,
merchant_id
and
action
=
'on_click_button'
and
int
(
split
(
app_version
,
'
\\
.'
)[
1
])
>=
31
)
ai
on
a
.
user_id
=
ai
.
user_id
and
a
.
partition_date
=
ai
.
partition_date
GROUP
BY
a
.
user_id
,
a
.
merchant_id
,
substr
(
a
.
partition_date
,
1
,
6
)
)
a
)
a
join
group
by
partition_date
,
user_id
)
t8
ON
a
.
partition_day
=
t8
.
partition_date
and
a
.
user_id
=
t8
.
user_id
left
join
(
--t4以上商户私信线索总数
SELECT
msg
.
partition_date
,
user_id
,
count
(
msg
.
merchant_id
)
as
msg_num
FROM
(
(
SELECT
user_id
,
merchant_id
,
partition_day
SELECT
user_id
,
merchant_id
,
SUBSTR
(
partition_day
,
1
,
6
)
AS
MONTH
,
min
(
partition_day
)
as
partition_date
FROM
ml
.
ml_c_et_msg_conversation_dimen_inc_d
--新仓库私信表
FROM
ml
.
ml_c_et_msg_conversation_dimen_inc_d
--新仓库私信表
WHERE
partition_day
>=
REGEXP_REPLACE
(
trunc
(
date_sub
(
current_date
(),
1
),
'MM'
),
'-'
,
''
)
WHERE
partition_day
>=
REGEXP_REPLACE
(
trunc
(
date_sub
(
current_date
(),
1
),
'MM'
),
'-'
,
''
)
AND
partition_day
<=
regexp_replace
(
date_sub
(
current_date
,
1
),
'-'
,
''
)
AND
partition_day
<=
regexp_replace
(
date_sub
(
current_date
,
1
),
'-'
,
''
)
GROUP
BY
user_id
,
merchant_id
,
partition_day
group
by
user_id
,
merchant_id
,
SUBSTR
(
partition_day
,
1
,
6
)
)
b
)
msg
on
a
.
user_id
=
b
.
user_id
and
a
.
merchant_id
=
b
.
merchant_id
and
a
.
partition_date
=
b
.
partition_day
join
group
by
a
.
user_id
,
a
.
merchant_id
,
substr
(
partition_day
,
1
,
6
)
)
msg
group
by
msg
.
partition_date
,
user_id
)
t7
on
a
.
partition_date
=
t7
.
partition_date
and
a
.
user_id
=
t7
.
user_id
left
join
(
--需求自测私信
SELECT
msg
.
partition_date
,
user_id
,
count
(
msg
.
merchant_id
)
as
valid_msg_num
FROM
(
SELECT
a
.
user_id
,
a
.
merchant_id
,
substr
(
partition_day
,
1
,
6
)
as
month
,
min
(
partition_day
)
as
partition_date
FROM
(
(
SELECT
partition_date
,
user_id
,
merchant_id
SELECT
distinct
merchant_id
from
FROM
(
--点击发送
SELECT
a
.
partition_date
,
user_id
,
cl_id
,
json_map
(
b
.
hospital_id
,
'string,string'
)[
'hospital_id'
]
hospital_id
FROM
(
SELECT
partition_date
,
user_id
,
cl_id
,
json_split
(
params
[
'hospital_id_list'
])
as
hospital_id_list
FROM
online
.
bl_hdfs_maidian_updates
where
partition_date
>=
REGEXP_REPLACE
(
trunc
(
date_sub
(
current_date
(),
1
),
'MM'
),
'-'
,
''
)
AND
partition_date
<=
regexp_replace
(
date_sub
(
current_date
,
1
),
'-'
,
''
)
and
page_name
=
'ai_plan_consult_list'
and
params
[
'button_name'
]
in
(
'send'
)
and
action
=
'on_click_button'
and
int
(
split
(
app_version
,
'
\\
.'
)[
1
])
>=
31
group
by
partition_date
,
user_id
,
cl_id
,
params
[
'hospital_id_list'
]
)
a
LATERAL
VIEW
EXPLODE
(
a
.
hospital_id_list
)
b
as
hospital_id
)
b
join
(
(
SELECT
hospital_id
,
merchant_id
SELECT
merchant_id
,
merchant_level
FROM
online
.
ml_doctor_relation_dimen_day
,
row_number
()
over
(
partition
by
merchant_id
order
by
data_month
desc
)
as
rn
WHERE
partition_date
=
regexp_replace
(
date_sub
(
current_date
,
1
),
'-'
,
''
)
FROM
online
.
al_business_merchant_grade_day_repo
AND
doctor_is_merchant
=
'true'
--医生是商户
where
partition_date
=
regexp_replace
(
date_sub
(
current_date
,
1
),
'-'
,
''
)
GROUP
BY
hospital_id
,
merchant_id
)
a
)
c
where
((
rn
=
1
and
merchant_level
>=
4
)
or
merchant_id
in
(
'6329571003697540960'
))
on
c
.
hospital_id
=
b
.
hospital_id
and
merchant_id
not
in
(
'6385685250516781117'
)
--去除和增加是为了和王妍的线索通数据保持一致
group
by
partition_date
,
user_id
,
merchant_id
)
b
)
a
on
msg
.
merchant_id
=
b
.
merchant_id
join
GROUP
BY
msg
.
partition_date
,
user_id
)
t10
ON
a
.
partition_day
=
t10
.
partition_date
and
a
.
user_id
=
t10
.
user_id
left
join
(
--t4以上商户有效私信线索总数
SELECT
msg
.
partition_date
,
user_id
,
count
(
msg
.
merchant_id
)
as
valid_msg_num
FROM
(
(
SELECT
user_id
,
merchant_id
,
partition_day
SELECT
user_id
,
merchant_id
,
SUBSTR
(
partition_day
,
1
,
6
)
AS
MONTH
,
min
(
partition_day
)
as
partition_date
FROM
ml
.
ml_c_et_msg_conversation_dimen_inc_d
--新仓库私信表
FROM
ml
.
ml_c_et_msg_conversation_dimen_inc_d
--新仓库私信表
WHERE
partition_day
>=
REGEXP_REPLACE
(
trunc
(
date_sub
(
current_date
(),
1
),
'MM'
),
'-'
,
''
)
WHERE
partition_day
>=
REGEXP_REPLACE
(
trunc
(
date_sub
(
current_date
(),
1
),
'MM'
),
'-'
,
''
)
AND
partition_day
<=
regexp_replace
(
date_sub
(
current_date
,
1
),
'-'
,
''
)
AND
partition_day
<=
regexp_replace
(
date_sub
(
current_date
,
1
),
'-'
,
''
)
and
is_valid
=
'true'
and
is_valid
=
'true'
GROUP
BY
user_id
,
merchant_id
,
partition_day
GROUP
BY
user_id
,
merchant_id
,
SUBSTR
(
partition_day
,
1
,
6
)
)
msg
join
(
SELECT
distinct
merchant_id
FROM
(
SELECT
merchant_id
,
merchant_level
,
row_number
()
over
(
partition
by
merchant_id
order
by
data_month
desc
)
as
rn
FROM
online
.
al_business_merchant_grade_day_repo
where
partition_date
=
regexp_replace
(
date_sub
(
current_date
,
1
),
'-'
,
''
)
)
a
where
((
rn
=
1
and
merchant_level
>=
4
)
or
merchant_id
in
(
'6329571003697540960'
))
and
merchant_id
not
in
(
'6385685250516781117'
)
--去除和增加是为了和王妍的线索通数据保持一致
)
b
)
b
on
a
.
user_id
=
b
.
user_id
and
a
.
merchant_id
=
b
.
merchant_id
and
a
.
partition_date
=
b
.
partition_day
on
msg
.
merchant_id
=
b
.
merchant_id
group
by
a
.
user_id
,
a
.
merchant_id
,
substr
(
partition_day
,
1
,
6
)
GROUP
BY
msg
.
partition_date
,
user_id
)
msg
)
t10_v
group
by
msg
.
partition_date
,
user_id
ON
a
.
partition_day
=
t10_v
.
partition_date
and
a
.
user_id
=
t10_v
.
user_id
)
t7_v
left
join
on
a
.
partition_date
=
t7_v
.
partition_date
and
a
.
user_id
=
t7_v
.
user_id
(
--t4以上商户电话线索总数
LEFT
JOIN
SELECT
partition_date
,
user_id
,
count
(
1
)
AS
clue_num
(
--需求自测电话线索总数
SELECT
partition_date
,
user_id
,
count
(
1
)
as
clue_num
FROM
(
SELECT
a
.
user_id
,
a
.
merchant_id
,
substr
(
a
.
partition_date
,
1
,
6
)
as
month
,
min
(
a
.
partition_date
)
as
partition_date
FROM
FROM
(
(
SELECT
user_id
,
merchant_id
,
REGEXP_REPLACE
(
SUBSTR
(
created_time
,
1
,
10
),
'-'
,
''
)
as
partition_date
SELECT
user_id
,
merchant_id
,
MIN
(
REGEXP_REPLACE
(
SUBSTR
(
created_time
,
1
,
10
),
'-'
,
''
))
as
partition_date
,
regexp_replace
(
SUBSTR
(
created_time
,
1
,
7
),
'-'
,
''
)
AS
CALL_MONTH
FROM
tl
.
tl_gm_sl_lead_task
--线索任务表(用户点击授权后记入该表)
FROM
tl
.
tl_gm_sl_lead_task
--线索任务表(用户点击授权后记入该表)
WHERE
partition_day
>=
REGEXP_REPLACE
(
trunc
(
date_sub
(
current_date
(),
1
),
'MM'
),
'-'
,
''
)
WHERE
partition_day
>=
REGEXP_REPLACE
(
trunc
(
date_sub
(
current_date
(),
1
),
'MM'
),
'-'
,
''
)
AND
partition_day
<=
regexp_replace
(
date_sub
(
current_date
(),
1
),
'-'
,
''
)
AND
partition_day
<=
regexp_replace
(
date_sub
(
current_date
(),
1
),
'-'
,
''
)
AND
source
=
'2'
--用户行为电话授权
AND
source
=
'2'
--用户行为电话授权
GROUP
BY
user_id
,
merchant_id
,
regexp_replace
(
SUBSTR
(
created_time
,
1
,
10
),
'-'
,
''
)
GROUP
BY
user_id
,
merchant_id
,
regexp_replace
(
SUBSTR
(
created_time
,
1
,
7
),
'-'
,
''
)
)
a
)
a
join
join
(
(
SELECT
partition_date
,
cl_id
,
user_id
SELECT
distinct
merchant_id
FROM
online
.
bl_hdfs_maidian_updates
FROM
where
partition_date
>=
REGEXP_REPLACE
(
trunc
(
date_sub
(
current_date
(),
1
),
'MM'
),
'-'
,
''
)
(
AND
partition_date
<=
regexp_replace
(
date_sub
(
current_date
,
1
),
'-'
,
''
)
SELECT
merchant_id
,
merchant_level
and
params
[
'popup_name'
]
=
'bargain_phone'
,
row_number
()
over
(
partition
by
merchant_id
order
by
data_month
desc
)
as
rn
and
page_name
=
'ai_plan_list'
FROM
online
.
al_business_merchant_grade_day_repo
and
params
[
'button_name'
]
in
(
'confirm'
)
where
partition_date
=
regexp_replace
(
date_sub
(
current_date
,
1
),
'-'
,
''
)
and
action
=
'on_click_button'
)
a
and
int
(
split
(
app_version
,
'
\\
.'
)[
1
])
>=
31
where
((
rn
=
1
and
merchant_level
>=
4
)
or
merchant_id
in
(
'6329571003697540960'
))
)
ai
and
merchant_id
not
in
(
'6385685250516781117'
)
--去除和增加是为了和王妍的线索通数据保持一致
on
a
.
user_id
=
ai
.
user_id
and
a
.
partition_date
=
ai
.
partition_date
GROUP
BY
a
.
user_id
,
a
.
merchant_id
,
substr
(
a
.
partition_date
,
1
,
6
)
)
a
group
by
partition_date
,
user_id
)
t8
ON
a
.
partition_date
=
t8
.
partition_date
and
a
.
user_id
=
t8
.
user_id
LEFT
JOIN
(
---拨打电话线索
SELECT
partition_date
,
user_id
,
count
(
1
)
as
call_num
FROM
(
SELECT
e
.
user_id
,
e
.
merchant_id
,
regexp_replace
(
SUBSTR
(
a
.
partition_date
,
1
,
6
),
'-'
,
''
)
AS
CALL_MONTH
,
MIN
(
a
.
partition_date
)
as
partition_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
(
trunc
(
date_sub
(
current_date
(),
1
),
'MM'
),
'-'
,
''
)
AND
REGEXP_REPLACE
(
SUBSTR
(
call_time
,
0
,
10
),
'-'
,
''
)
<=
regexp_replace
(
date_sub
(
current_date
(),
1
),
'-'
,
''
)
and
start_time
>
call_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
)
b
ON
a
.
sub_id
=
b
.
sub_id
on
a
.
merchant_id
=
b
.
merchant_id
LEFT
JOIN
GROUP
BY
partition_date
,
user_id
(
)
t11
SELECT
id
,
platform_binding_id
ON
a
.
partition_day
=
t11
.
partition_date
and
a
.
user_id
=
t11
.
user_id
FROM
tl
.
tl_gm_sl_virtual_phone_binding
group
by
mas
.
partition_date
,
device_os_type
,
active_type
,
grey_type
WHERE
partition_day
=
regexp_replace
(
date_sub
(
current_date
,
1
),
'-'
,
''
)
)
T1
)
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
,
REGEXP_REPLACE
(
SUBSTR
(
created_time
,
1
,
10
),
'-'
,
''
)
as
partition_date
FROM
tl
.
tl_gm_sl_lead_task
--线索任务表(用户点击授权后记入该表)
WHERE
partition_day
>=
REGEXP_REPLACE
(
trunc
(
date_sub
(
current_date
(),
1
),
'MM'
),
'-'
,
''
)
AND
partition_day
<=
regexp_replace
(
date_sub
(
current_date
(),
1
),
'-'
,
''
)
AND
source
=
'2'
--用户行为电话授权
group
by
id
,
user_id
,
merchant_id
,
created_time
)
e
ON
d
.
lead_task_id
=
e
.
id
join
(
SELECT
partition_date
,
cl_id
,
user_id
FROM
online
.
bl_hdfs_maidian_updates
where
partition_date
>=
REGEXP_REPLACE
(
trunc
(
date_sub
(
current_date
(),
1
),
'MM'
),
'-'
,
''
)
AND
partition_date
<=
regexp_replace
(
date_sub
(
current_date
,
1
),
'-'
,
''
)
and
params
[
'popup_name'
]
=
'bargain_phone'
and
page_name
=
'ai_plan_list'
and
params
[
'button_name'
]
in
(
'confirm'
)
and
action
=
'on_click_button'
and
int
(
split
(
app_version
,
'
\\
.'
)[
1
])
>=
31
)
ai
on
e
.
user_id
=
ai
.
user_id
and
e
.
partition_date
=
ai
.
partition_date
GROUP
BY
e
.
user_id
,
e
.
merchant_id
,
regexp_replace
(
SUBSTR
(
a
.
partition_date
,
1
,
6
),
'-'
,
''
)
)
t1
GROUP
BY
user_id
,
partition_date
)
t9
ON
a
.
partition_date
=
t9
.
partition_date
and
a
.
user_id
=
t9
.
user_id
LEFT
JOIN
LEFT
JOIN
(
---拨打电话线索
(
SELECT
partition_date
,
user_id
SELECT
t3
.
partition_date
,
a
.
device_os_type
,
'老活跃设备'
as
active_type
,
a
.
grey_type
,
count
(
1
)
as
valid_call_num
,
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
,
count
(
distinct
case
when
t12
.
call_num
>
0
then
t12
.
user_id
end
)
as
call_dev_4
,
sum
(
t12
.
call_num
)
as
call_num_4
,
count
(
distinct
case
when
t12_v
.
valid_call_num
>
0
then
t12_v
.
user_id
end
)
as
valid_call_dev_4
,
sum
(
t12_v
.
valid_call_num
)
as
valid_call_num_4
,
count
(
distinct
case
when
t6
.
call_num
>
0
then
t6
.
user_id
end
)
as
call_dev_kyc
,
sum
(
t6
.
call_num
)
as
call_num_kyc
,
count
(
distinct
case
when
t6_v
.
valid_call_num
>
0
then
t6_v
.
user_id
end
)
as
valid_call_dev_kyc
,
sum
(
t6_v
.
valid_call_num
)
as
valid_call_num_kyc
,
count
(
distinct
case
when
t9
.
call_num
>
0
then
t9
.
user_id
end
)
as
call_dev_qa
,
sum
(
t9
.
call_num
)
as
call_num_qa
,
count
(
distinct
case
when
t9_v
.
valid_call_num
>
0
then
t9_v
.
user_id
end
)
as
valid_call_dev_qa
,
sum
(
t9_v
.
valid_call_num
)
as
valid_call_num_qa
FROM
FROM
(
(
SELECT
e
.
user_id
,
e
.
merchant_id
,
regexp_replace
(
SUBSTR
(
a
.
partition_date
,
1
,
6
),
'-'
,
''
)
AS
CALL_MONTH
,
SELECT
device_id
,
device_os_type
,
user_id
,
v
.
grey_type
MIN
(
a
.
partition_date
)
as
partition_date
,
1
as
call_num
FROM
FROM
(
(
SELECT
sub_id
,
REGEXP_REPLACE
(
SUBSTR
(
call_time
,
0
,
10
),
'-'
,
''
)
as
partition_date
SELECT
device_id
,
device_os_type
,
user_id
FROM
tl
.
tl_gm_sl_ali_virtual_phone_call_detail
--通话记录表,call_type呼叫类型
,
array
(
case
when
substr
(
convup
(
setencryption
(
device_id
,
'sha-1'
),
16
,
10
),
-
2
,
2
)
%
20
=
0
then
'kyc灰度'
else
'非灰'
end
,
'合计'
)
as
grey_type
WHERE
partition_day
=
regexp_replace
(
date_sub
(
current_date
,
1
),
'-'
,
''
)
FROM
AND
REGEXP_REPLACE
(
SUBSTR
(
call_time
,
0
,
10
),
'-'
,
''
)
>=
REGEXP_REPLACE
(
trunc
(
date_sub
(
current_date
(),
1
),
'MM'
),
'-'
,
''
)
(
AND
REGEXP_REPLACE
(
SUBSTR
(
call_time
,
0
,
10
),
'-'
,
''
)
<=
regexp_replace
(
date_sub
(
current_date
(),
1
),
'-'
,
''
)
SELECT
device_id
,
device_os_type
,
a
.
user_id
and
start_time
>
call_time
,
row_number
()
over
(
partition
by
device_id
order
by
a
.
partition_day
desc
)
as
rn
and
unix_timestamp
(
substr
(
start_time
,
1
,
19
))
+
30
<=
unix_timestamp
(
substr
(
release_time
,
1
,
19
))
FROM
)
a
(
LEFT
JOIN
SELECT
device_id
,
device_os_type
,
v
.
user_id
,
partition_day
(
FROM
ml
.
mid_ml_c_ct_dv_device_inc_d
SELECT
id
,
sub_id
LATERAL
VIEW
EXPLODE
(
user_id_list
)
v
as
user_id
FROM
tl
.
tl_gm_sl_ali_virtual_phone_binding
--阿里记录表
where
partition_day
>=
'20200801'
and
partition_day
<=
regexp_replace
(
date_sub
(
current_date
(),
1
),
'-'
,
''
)
WHERE
partition_day
=
regexp_replace
(
date_sub
(
current_date
,
1
),
'-'
,
''
)
)
a
--由于要取近期该设备用过的user_id,故时间取的较长,避免用公式而将月末数据少算
)
b
join
ON
a
.
sub_id
=
b
.
sub_id
(
LEFT
JOIN
SELECT
partition_day
,
user_id
(
FROM
ml
.
ml_c_ct_ui_user_dimen_inc_d
SELECT
id
,
platform_binding_id
where
partition_day
>=
'20200801'
and
partition_day
<=
regexp_replace
(
date_sub
(
current_date
(),
1
),
'-'
,
''
)
FROM
tl
.
tl_gm_sl_virtual_phone_binding
and
size
(
user_phone_list
)
>
0
WHERE
partition_day
=
regexp_replace
(
date_sub
(
current_date
,
1
),
'-'
,
''
)
group
by
partition_day
,
user_id
)
c
)
b
ON
b
.
id
=
c
.
platform_binding_id
on
a
.
partition_day
=
b
.
partition_day
and
a
.
user_id
=
b
.
user_id
LEFT
JOIN
)
c
(
where
rn
=
1
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
)
d
ON
c
.
id
=
d
.
phone_binding_id
LATERAL
VIEW
EXPLODE
(
d
.
grey_type
)
v
as
grey_type
JOIN
)
a
(
JOIN
SELECT
id
,
user_id
,
merchant_id
,
REGEXP_REPLACE
(
SUBSTR
(
created_time
,
1
,
10
),
'-'
,
''
)
as
partition_date
(
---拨打电话线索
FROM
tl
.
tl_gm_sl_lead_task
--线索任务表(用户点击授权后记入该表)
SELECT
partition_date
,
user_id
WHERE
partition_day
>=
REGEXP_REPLACE
(
trunc
(
date_sub
(
current_date
(),
1
),
'MM'
),
'-'
,
''
)
,
count
(
1
)
as
call_num
AND
partition_day
<=
regexp_replace
(
date_sub
(
current_date
(),
1
),
'-'
,
''
)
AND
source
=
'2'
--用户行为电话授权
group
by
id
,
user_id
,
merchant_id
,
created_time
)
e
ON
d
.
lead_task_id
=
e
.
id
join
(
SELECT
partition_date
,
cl_id
,
user_id
FROM
online
.
bl_hdfs_maidian_updates
where
partition_date
>=
REGEXP_REPLACE
(
trunc
(
date_sub
(
current_date
(),
1
),
'MM'
),
'-'
,
''
)
AND
partition_date
<=
regexp_replace
(
date_sub
(
current_date
,
1
),
'-'
,
''
)
and
params
[
'popup_name'
]
=
'bargain_phone'
and
page_name
=
'ai_plan_list'
and
params
[
'button_name'
]
in
(
'confirm'
)
and
action
=
'on_click_button'
and
int
(
split
(
app_version
,
'
\\
.'
)[
1
])
>=
31
)
ai
on
e
.
user_id
=
ai
.
user_id
and
e
.
partition_date
=
ai
.
partition_date
GROUP
BY
e
.
user_id
,
e
.
merchant_id
,
regexp_replace
(
SUBSTR
(
a
.
partition_date
,
1
,
6
),
'-'
,
''
)
)
t1
GROUP
BY
user_id
,
partition_date
)
t9_v
ON
a
.
partition_date
=
t9_v
.
partition_date
and
a
.
user_id
=
t9_v
.
user_id
left
join
(
--t4以上商户私信线索总数
SELECT
msg
.
partition_date
,
user_id
,
count
(
msg
.
merchant_id
)
as
msg_num
FROM
(
SELECT
user_id
,
merchant_id
,
SUBSTR
(
partition_day
,
1
,
6
)
AS
MONTH
,
min
(
partition_day
)
as
partition_date
FROM
ml
.
ml_c_et_msg_conversation_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
),
'-'
,
''
)
group
by
user_id
,
merchant_id
,
SUBSTR
(
partition_day
,
1
,
6
)
)
msg
join
(
SELECT
distinct
merchant_id
FROM
FROM
(
(
SELECT
merchant_id
,
merchant_level
SELECT
user_id
,
merchant_id
,
regexp_replace
(
SUBSTR
(
a
.
partition_date
,
1
,
6
),
'-'
,
''
)
AS
CALL_MONTH
,
,
row_number
()
over
(
partition
by
merchant_id
order
by
data_month
desc
)
as
rn
MIN
(
partition_date
)
as
partition_date
,
FROM
online
.
al_business_merchant_grade_day_repo
1
as
call_num
where
partition_date
=
regexp_replace
(
date_sub
(
current_date
,
1
),
'-'
,
''
)
FROM
)
a
(
where
((
rn
=
1
and
merchant_level
>=
4
)
or
merchant_id
in
(
'6329571003697540960'
))
SELECT
sub_id
,
REGEXP_REPLACE
(
SUBSTR
(
call_time
,
0
,
10
),
'-'
,
''
)
as
partition_date
and
merchant_id
not
in
(
'6385685250516781117'
)
--去除和增加是为了和王妍的线索通数据保持一致
FROM
tl
.
tl_gm_sl_ali_virtual_phone_call_detail
--通话记录表,call_type呼叫类型
)
b
WHERE
partition_day
=
regexp_replace
(
date_sub
(
current_date
,
1
),
'-'
,
''
)
on
msg
.
merchant_id
=
b
.
merchant_id
AND
REGEXP_REPLACE
(
SUBSTR
(
call_time
,
0
,
10
),
'-'
,
''
)
>=
REGEXP_REPLACE
(
trunc
(
date_sub
(
current_date
(),
1
),
'MM'
),
'-'
,
''
)
GROUP
BY
msg
.
partition_date
,
user_id
AND
REGEXP_REPLACE
(
SUBSTR
(
call_time
,
0
,
10
),
'-'
,
''
)
<=
regexp_replace
(
date_sub
(
current_date
(),
1
),
'-'
,
''
)
)
t10
and
start_time
>
call_time
ON
a
.
partition_date
=
t10
.
partition_date
and
a
.
user_id
=
t10
.
user_id
)
a
left
join
LEFT
JOIN
(
--有效私信线索总数
(
SELECT
msg
.
partition_date
,
user_id
SELECT
id
,
sub_id
,
count
(
msg
.
merchant_id
)
as
valid_msg_num
FROM
tl
.
tl_gm_sl_ali_virtual_phone_binding
--阿里记录表
FROM
WHERE
partition_day
=
regexp_replace
(
date_sub
(
current_date
,
1
),
'-'
,
''
)
(
)
b
SELECT
user_id
,
merchant_id
,
SUBSTR
(
partition_day
,
1
,
6
)
AS
MONTH
,
min
(
partition_day
)
as
partition_date
ON
a
.
sub_id
=
b
.
sub_id
FROM
ml
.
ml_c_et_msg_conversation_dimen_inc_d
--新仓库私信表
LEFT
JOIN
WHERE
partition_day
>=
REGEXP_REPLACE
(
trunc
(
date_sub
(
current_date
(),
1
),
'MM'
),
'-'
,
''
)
(
AND
partition_day
<=
regexp_replace
(
date_sub
(
current_date
,
1
),
'-'
,
''
)
SELECT
id
,
platform_binding_id
and
is_valid
=
'true'
FROM
tl
.
tl_gm_sl_virtual_phone_binding
GROUP
BY
user_id
,
merchant_id
,
SUBSTR
(
partition_day
,
1
,
6
)
WHERE
partition_day
=
regexp_replace
(
date_sub
(
current_date
,
1
),
'-'
,
''
)
)
msg
)
c
join
ON
b
.
id
=
c
.
platform_binding_id
(
LEFT
JOIN
SELECT
distinct
merchant_id
(
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'
--用户行为电话授权
)
e
ON
d
.
lead_task_id
=
e
.
id
GROUP
BY
user_id
,
merchant_id
,
regexp_replace
(
SUBSTR
(
a
.
partition_date
,
1
,
6
),
'-'
,
''
)
)
t1
GROUP
BY
user_id
,
partition_date
)
t3
ON
a
.
user_id
=
t3
.
user_id
LEFT
JOIN
(
---拨打电话线索
SELECT
partition_date
,
user_id
,
count
(
1
)
as
valid_call_num
FROM
FROM
(
(
SELECT
merchant_id
,
merchant_level
SELECT
user_id
,
merchant_id
,
regexp_replace
(
SUBSTR
(
a
.
partition_date
,
1
,
6
),
'-'
,
''
)
AS
CALL_MONTH
,
,
row_number
()
over
(
partition
by
merchant_id
order
by
data_month
desc
)
as
rn
MIN
(
partition_date
)
as
partition_date
,
FROM
online
.
al_business_merchant_grade_day_repo
1
as
call_num
where
partition_date
=
regexp_replace
(
date_sub
(
current_date
,
1
),
'-'
,
''
)
FROM
)
a
(
where
((
rn
=
1
and
merchant_level
>=
4
)
or
merchant_id
in
(
'6329571003697540960'
))
SELECT
sub_id
,
REGEXP_REPLACE
(
SUBSTR
(
call_time
,
0
,
10
),
'-'
,
''
)
as
partition_date
and
merchant_id
not
in
(
'6385685250516781117'
)
--去除和增加是为了和王妍的线索通数据保持一致
FROM
tl
.
tl_gm_sl_ali_virtual_phone_call_detail
--通话记录表,call_type呼叫类型
)
b
WHERE
partition_day
=
regexp_replace
(
date_sub
(
current_date
,
1
),
'-'
,
''
)
on
msg
.
merchant_id
=
b
.
merchant_id
AND
REGEXP_REPLACE
(
SUBSTR
(
call_time
,
0
,
10
),
'-'
,
''
)
>=
REGEXP_REPLACE
(
trunc
(
date_sub
(
current_date
(),
1
),
'MM'
),
'-'
,
''
)
GROUP
BY
msg
.
partition_date
,
user_id
AND
REGEXP_REPLACE
(
SUBSTR
(
call_time
,
0
,
10
),
'-'
,
''
)
<=
regexp_replace
(
date_sub
(
current_date
(),
1
),
'-'
,
''
)
)
t10_v
and
start_time
>
call_time
ON
a
.
partition_date
=
t10_v
.
partition_date
and
a
.
user_id
=
t10_v
.
user_id
and
unix_timestamp
(
substr
(
start_time
,
1
,
19
))
+
30
<=
unix_timestamp
(
substr
(
release_time
,
1
,
19
))
left
join
)
a
(
--t4以上商户电话线索总数
LEFT
JOIN
SELECT
partition_date
,
user_id
,
count
(
1
)
AS
clue_num
(
FROM
SELECT
id
,
sub_id
(
FROM
tl
.
tl_gm_sl_ali_virtual_phone_binding
--阿里记录表
SELECT
user_id
,
merchant_id
,
MIN
(
REGEXP_REPLACE
(
SUBSTR
(
created_time
,
1
,
10
),
'-'
,
''
))
as
partition_date
,
regexp_replace
(
SUBSTR
(
created_time
,
1
,
7
),
'-'
,
''
)
AS
CALL_MONTH
WHERE
partition_day
=
regexp_replace
(
date_sub
(
current_date
,
1
),
'-'
,
''
)
FROM
tl
.
tl_gm_sl_lead_task
--线索任务表(用户点击授权后记入该表)
)
b
WHERE
partition_day
>=
REGEXP_REPLACE
(
trunc
(
date_sub
(
current_date
(),
1
),
'MM'
),
'-'
,
''
)
ON
a
.
sub_id
=
b
.
sub_id
AND
partition_day
<=
regexp_replace
(
date_sub
(
current_date
(),
1
),
'-'
,
''
)
LEFT
JOIN
AND
source
=
'2'
--用户行为电话授权
(
GROUP
BY
user_id
,
merchant_id
,
regexp_replace
(
SUBSTR
(
created_time
,
1
,
7
),
'-'
,
''
)
SELECT
id
,
platform_binding_id
)
a
FROM
tl
.
tl_gm_sl_virtual_phone_binding
join
WHERE
partition_day
=
regexp_replace
(
date_sub
(
current_date
,
1
),
'-'
,
''
)
(
)
c
SELECT
distinct
merchant_id
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'
--用户行为电话授权
)
e
ON
d
.
lead_task_id
=
e
.
id
GROUP
BY
user_id
,
merchant_id
,
regexp_replace
(
SUBSTR
(
a
.
partition_date
,
1
,
6
),
'-'
,
''
)
)
t1
GROUP
BY
user_id
,
partition_date
)
t3_v
ON
t3
.
partition_date
=
t3_v
.
partition_date
and
t3
.
user_id
=
t3_v
.
user_id
LEFT
JOIN
(
--拨打电话线索
SELECT
partition_date
,
user_id
,
count
(
1
)
as
call_num
FROM
FROM
(
(
SELECT
merchant_id
,
merchant_level
SELECT
e
.
user_id
,
e
.
merchant_id
,
regexp_replace
(
SUBSTR
(
a
.
partition_date
,
1
,
6
),
'-'
,
''
)
AS
CALL_MONTH
,
,
row_number
()
over
(
partition
by
merchant_id
order
by
data_month
desc
)
as
rn
MIN
(
a
.
partition_date
)
as
partition_date
,
FROM
online
.
al_business_merchant_grade_day_repo
1
as
call_num
where
partition_date
=
regexp_replace
(
date_sub
(
current_date
,
1
),
'-'
,
''
)
FROM
)
a
(
where
((
rn
=
1
and
merchant_level
>=
4
)
or
merchant_id
in
(
'6329571003697540960'
))
SELECT
sub_id
,
REGEXP_REPLACE
(
SUBSTR
(
call_time
,
0
,
10
),
'-'
,
''
)
as
partition_date
and
merchant_id
not
in
(
'6385685250516781117'
)
--去除和增加是为了和王妍的线索通数据保持一致
FROM
tl
.
tl_gm_sl_ali_virtual_phone_call_detail
--通话记录表,call_type呼叫类型
)
b
WHERE
partition_day
=
regexp_replace
(
date_sub
(
current_date
,
1
),
'-'
,
''
)
on
a
.
merchant_id
=
b
.
merchant_id
AND
REGEXP_REPLACE
(
SUBSTR
(
call_time
,
0
,
10
),
'-'
,
''
)
>=
REGEXP_REPLACE
(
trunc
(
date_sub
(
current_date
(),
1
),
'MM'
),
'-'
,
''
)
GROUP
BY
partition_date
,
user_id
AND
REGEXP_REPLACE
(
SUBSTR
(
call_time
,
0
,
10
),
'-'
,
''
)
<=
regexp_replace
(
date_sub
(
current_date
(),
1
),
'-'
,
''
)
)
t11
and
start_time
>
call_time
ON
a
.
partition_date
=
t11
.
partition_date
and
a
.
user_id
=
t11
.
user_id
)
a
LEFT
JOIN
LEFT
JOIN
(
---拨打电话线索
(
SELECT
partition_date
,
user_id
SELECT
id
,
sub_id
,
count
(
1
)
as
call_num
FROM
tl
.
tl_gm_sl_ali_virtual_phone_binding
--阿里记录表
FROM
WHERE
partition_day
=
regexp_replace
(
date_sub
(
current_date
,
1
),
'-'
,
''
)
(
)
b
SELECT
user_id
,
merchant_id
,
regexp_replace
(
SUBSTR
(
a
.
partition_date
,
1
,
6
),
'-'
,
''
)
AS
CALL_MONTH
,
ON
a
.
sub_id
=
b
.
sub_id
MIN
(
partition_date
)
as
partition_date
,
LEFT
JOIN
1
as
call_num
(
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
,
REGEXP_REPLACE
(
SUBSTR
(
created_time
,
1
,
10
),
'-'
,
''
)
as
partition_date
FROM
tl
.
tl_gm_sl_lead_task
--线索任务表(用户点击授权后记入该表)
WHERE
partition_day
>=
REGEXP_REPLACE
(
trunc
(
date_sub
(
current_date
(),
1
),
'MM'
),
'-'
,
''
)
AND
partition_day
<=
regexp_replace
(
date_sub
(
current_date
(),
1
),
'-'
,
''
)
AND
source
=
'2'
--用户行为电话授权
group
by
id
,
user_id
,
merchant_id
,
created_time
)
e
ON
d
.
lead_task_id
=
e
.
id
join
(
SELECT
partition_date
,
user_id
,
merchant_id
from
(
SELECT
partition_date
,
cl_id
,
user_id
,
hospital_id
from
(
SELECT
partition_date
,
cl_id
,
user_id
,
json_split
(
params
[
'hospital_id'
],
'string'
)
as
hospital_ids
FROM
online
.
bl_hdfs_maidian_updates
where
partition_date
>=
REGEXP_REPLACE
(
trunc
(
date_sub
(
current_date
(),
1
),
'MM'
),
'-'
,
''
)
AND
partition_date
<=
regexp_replace
(
date_sub
(
current_date
,
1
),
'-'
,
''
)
and
page_name
in
(
'kyc_phone'
)
and
action
=
'on_click_button'
and
params
[
'button_name'
]
=
'agree'
and
params
[
'hospital_id'
]
like
'%[%'
--其实传的是doctor_id
)
a
LATERAL
VIEW
explode
(
hospital_ids
)
b
AS
hospital_id
group
by
partition_date
,
cl_id
,
user_id
,
hospital_id
)
a
join
(
SELECT
doctor_id
,
merchant_id
FROM
online
.
ml_doctor_relation_dimen_day
WHERE
partition_date
=
regexp_replace
(
date_sub
(
current_date
,
1
),
'-'
,
''
)
AND
doctor_is_merchant
=
'true'
--医生是商户
GROUP
BY
doctor_id
,
merchant_id
)
b
on
a
.
hospital_id
=
b
.
doctor_id
)
kyc
on
e
.
user_id
=
kyc
.
user_id
and
e
.
merchant_id
=
kyc
.
merchant_id
and
e
.
partition_date
=
kyc
.
partition_date
GROUP
BY
e
.
user_id
,
e
.
merchant_id
,
regexp_replace
(
SUBSTR
(
a
.
partition_date
,
1
,
6
),
'-'
,
''
)
)
t1
GROUP
BY
user_id
,
partition_date
)
t6
ON
t3
.
partition_date
=
t6
.
partition_date
and
t3
.
user_id
=
t6
.
user_id
LEFT
JOIN
(
---拨打电话线索
SELECT
partition_date
,
user_id
,
count
(
1
)
as
valid_call_num
FROM
FROM
(
(
SELECT
sub_id
,
REGEXP_REPLACE
(
SUBSTR
(
call_time
,
0
,
10
),
'-'
,
''
)
as
partition_date
SELECT
e
.
user_id
,
e
.
merchant_id
,
regexp_replace
(
SUBSTR
(
a
.
partition_date
,
1
,
6
),
'-'
,
''
)
AS
CALL_MONTH
,
FROM
tl
.
tl_gm_sl_ali_virtual_phone_call_detail
--通话记录表,call_type呼叫类型
MIN
(
a
.
partition_date
)
as
partition_date
,
WHERE
partition_day
=
regexp_replace
(
date_sub
(
current_date
,
1
),
'-'
,
''
)
1
as
call_num
AND
REGEXP_REPLACE
(
SUBSTR
(
call_time
,
0
,
10
),
'-'
,
''
)
>=
REGEXP_REPLACE
(
trunc
(
date_sub
(
current_date
(),
1
),
'MM'
),
'-'
,
''
)
FROM
AND
REGEXP_REPLACE
(
SUBSTR
(
call_time
,
0
,
10
),
'-'
,
''
)
<=
regexp_replace
(
date_sub
(
current_date
(),
1
),
'-'
,
''
)
(
and
start_time
>
call_time
SELECT
sub_id
,
REGEXP_REPLACE
(
SUBSTR
(
call_time
,
0
,
10
),
'-'
,
''
)
as
partition_date
)
a
FROM
tl
.
tl_gm_sl_ali_virtual_phone_call_detail
--通话记录表,call_type呼叫类型
LEFT
JOIN
WHERE
partition_day
=
regexp_replace
(
date_sub
(
current_date
,
1
),
'-'
,
''
)
(
AND
REGEXP_REPLACE
(
SUBSTR
(
call_time
,
0
,
10
),
'-'
,
''
)
>=
REGEXP_REPLACE
(
trunc
(
date_sub
(
current_date
(),
1
),
'MM'
),
'-'
,
''
)
SELECT
id
,
sub_id
AND
REGEXP_REPLACE
(
SUBSTR
(
call_time
,
0
,
10
),
'-'
,
''
)
<=
regexp_replace
(
date_sub
(
current_date
(),
1
),
'-'
,
''
)
FROM
tl
.
tl_gm_sl_ali_virtual_phone_binding
--阿里记录表
and
start_time
>
call_time
WHERE
partition_day
=
regexp_replace
(
date_sub
(
current_date
,
1
),
'-'
,
''
)
and
unix_timestamp
(
substr
(
start_time
,
1
,
19
))
+
30
<=
unix_timestamp
(
substr
(
release_time
,
1
,
19
))
)
b
)
a
ON
a
.
sub_id
=
b
.
sub_id
LEFT
JOIN
LEFT
JOIN
(
(
SELECT
id
,
sub_id
SELECT
id
,
platform_binding_id
FROM
tl
.
tl_gm_sl_ali_virtual_phone_binding
--阿里记录表
FROM
tl
.
tl_gm_sl_virtual_phone_binding
WHERE
partition_day
=
regexp_replace
(
date_sub
(
current_date
,
1
),
'-'
,
''
)
WHERE
partition_day
=
regexp_replace
(
date_sub
(
current_date
,
1
),
'-'
,
''
)
)
b
)
c
ON
a
.
sub_id
=
b
.
sub_id
ON
b
.
id
=
c
.
platform_binding_id
LEFT
JOIN
LEFT
JOIN
(
(
SELECT
id
,
platform_binding_id
SELECT
phone_binding_id
,
lead_task_id
FROM
tl
.
tl_gm_sl_virtual_phone_binding
FROM
tl
.
tl_gm_sl_lead_task_phone_binding
WHERE
partition_day
=
regexp_replace
(
date_sub
(
current_date
,
1
),
'-'
,
''
)
WHERE
partition_day
=
regexp_replace
(
date_sub
(
current_date
,
1
),
'-'
,
''
)
)
c
)
d
ON
b
.
id
=
c
.
platform_binding_id
ON
c
.
id
=
d
.
phone_binding_id
LEFT
JOIN
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
,
REGEXP_REPLACE
(
SUBSTR
(
created_time
,
1
,
10
),
'-'
,
''
)
as
partition_date
FROM
tl
.
tl_gm_sl_lead_task
--线索任务表(用户点击授权后记入该表)
WHERE
partition_day
>=
REGEXP_REPLACE
(
trunc
(
date_sub
(
current_date
(),
1
),
'MM'
),
'-'
,
''
)
AND
partition_day
<=
regexp_replace
(
date_sub
(
current_date
(),
1
),
'-'
,
''
)
AND
source
=
'2'
--用户行为电话授权
group
by
id
,
user_id
,
merchant_id
,
created_time
)
e
ON
d
.
lead_task_id
=
e
.
id
join
(
SELECT
partition_date
,
user_id
,
merchant_id
from
(
SELECT
partition_date
,
cl_id
,
user_id
,
hospital_id
from
(
SELECT
partition_date
,
cl_id
,
user_id
,
json_split
(
params
[
'hospital_id'
],
'string'
)
as
hospital_ids
FROM
online
.
bl_hdfs_maidian_updates
where
partition_date
>=
REGEXP_REPLACE
(
trunc
(
date_sub
(
current_date
(),
1
),
'MM'
),
'-'
,
''
)
AND
partition_date
<=
regexp_replace
(
date_sub
(
current_date
,
1
),
'-'
,
''
)
and
page_name
in
(
'kyc_phone'
)
and
action
=
'on_click_button'
and
params
[
'button_name'
]
=
'agree'
and
params
[
'hospital_id'
]
like
'%[%'
--其实传的是doctor_id
)
a
LATERAL
VIEW
explode
(
hospital_ids
)
b
AS
hospital_id
group
by
partition_date
,
cl_id
,
user_id
,
hospital_id
)
a
join
(
SELECT
doctor_id
,
merchant_id
FROM
online
.
ml_doctor_relation_dimen_day
WHERE
partition_date
=
regexp_replace
(
date_sub
(
current_date
,
1
),
'-'
,
''
)
AND
doctor_is_merchant
=
'true'
--医生是商户
GROUP
BY
doctor_id
,
merchant_id
)
b
on
a
.
hospital_id
=
b
.
doctor_id
)
kyc
on
e
.
user_id
=
kyc
.
user_id
and
e
.
merchant_id
=
kyc
.
merchant_id
and
e
.
partition_date
=
kyc
.
partition_date
GROUP
BY
e
.
user_id
,
e
.
merchant_id
,
regexp_replace
(
SUBSTR
(
a
.
partition_date
,
1
,
6
),
'-'
,
''
)
)
t1
GROUP
BY
user_id
,
partition_date
)
t6_v
ON
t3
.
partition_date
=
t6_v
.
partition_date
and
t3
.
user_id
=
t6_v
.
user_id
LEFT
JOIN
(
---拨打电话线索
SELECT
partition_date
,
user_id
,
count
(
1
)
as
call_num
FROM
(
(
SELECT
id
,
user_id
,
merchant_id
SELECT
e
.
user_id
,
e
.
merchant_id
,
regexp_replace
(
SUBSTR
(
a
.
partition_date
,
1
,
6
),
'-'
,
''
)
AS
CALL_MONTH
,
FROM
tl
.
tl_gm_sl_lead_task
--线索任务表(用户点击授权后记入该表)
MIN
(
a
.
partition_date
)
as
partition_date
,
WHERE
partition_day
=
regexp_replace
(
date_sub
(
current_date
,
1
),
'-'
,
''
)
1
as
call_num
AND
source
=
'2'
--用户行为电话授权
FROM
)
e
(
ON
d
.
lead_task_id
=
e
.
id
SELECT
sub_id
,
REGEXP_REPLACE
(
SUBSTR
(
call_time
,
0
,
10
),
'-'
,
''
)
as
partition_date
GROUP
BY
user_id
,
merchant_id
,
regexp_replace
(
SUBSTR
(
a
.
partition_date
,
1
,
6
),
'-'
,
''
)
FROM
tl
.
tl_gm_sl_ali_virtual_phone_call_detail
--通话记录表,call_type呼叫类型
)
t1
WHERE
partition_day
=
regexp_replace
(
date_sub
(
current_date
,
1
),
'-'
,
''
)
join
AND
REGEXP_REPLACE
(
SUBSTR
(
call_time
,
0
,
10
),
'-'
,
''
)
>=
REGEXP_REPLACE
(
trunc
(
date_sub
(
current_date
(),
1
),
'MM'
),
'-'
,
''
)
(
AND
REGEXP_REPLACE
(
SUBSTR
(
call_time
,
0
,
10
),
'-'
,
''
)
<=
regexp_replace
(
date_sub
(
current_date
(),
1
),
'-'
,
''
)
SELECT
distinct
merchant_id
and
start_time
>
call_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
,
REGEXP_REPLACE
(
SUBSTR
(
created_time
,
1
,
10
),
'-'
,
''
)
as
partition_date
FROM
tl
.
tl_gm_sl_lead_task
--线索任务表(用户点击授权后记入该表)
WHERE
partition_day
>=
REGEXP_REPLACE
(
trunc
(
date_sub
(
current_date
(),
1
),
'MM'
),
'-'
,
''
)
AND
partition_day
<=
regexp_replace
(
date_sub
(
current_date
(),
1
),
'-'
,
''
)
AND
source
=
'2'
--用户行为电话授权
group
by
id
,
user_id
,
merchant_id
,
created_time
)
e
ON
d
.
lead_task_id
=
e
.
id
join
(
SELECT
partition_date
,
cl_id
,
user_id
FROM
online
.
bl_hdfs_maidian_updates
where
partition_date
>=
REGEXP_REPLACE
(
trunc
(
date_sub
(
current_date
(),
1
),
'MM'
),
'-'
,
''
)
AND
partition_date
<=
regexp_replace
(
date_sub
(
current_date
,
1
),
'-'
,
''
)
and
params
[
'popup_name'
]
=
'bargain_phone'
and
page_name
=
'ai_plan_list'
and
params
[
'button_name'
]
in
(
'confirm'
)
and
action
=
'on_click_button'
and
int
(
split
(
app_version
,
'
\\
.'
)[
1
])
>=
31
)
ai
on
e
.
user_id
=
ai
.
user_id
and
e
.
partition_date
=
ai
.
partition_date
GROUP
BY
e
.
user_id
,
e
.
merchant_id
,
regexp_replace
(
SUBSTR
(
a
.
partition_date
,
1
,
6
),
'-'
,
''
)
)
t1
GROUP
BY
user_id
,
partition_date
)
t9
ON
t3
.
partition_date
=
t9
.
partition_date
and
t3
.
user_id
=
t9
.
user_id
LEFT
JOIN
(
---拨打电话线索
SELECT
partition_date
,
user_id
,
count
(
1
)
as
valid_call_num
FROM
FROM
(
(
SELECT
merchant_id
,
merchant_level
SELECT
e
.
user_id
,
e
.
merchant_id
,
regexp_replace
(
SUBSTR
(
a
.
partition_date
,
1
,
6
),
'-'
,
''
)
AS
CALL_MONTH
,
,
row_number
()
over
(
partition
by
merchant_id
order
by
data_month
desc
)
as
rn
MIN
(
a
.
partition_date
)
as
partition_date
,
FROM
online
.
al_business_merchant_grade_day_repo
1
as
call_num
where
partition_date
=
regexp_replace
(
date_sub
(
current_date
,
1
),
'-'
,
''
)
FROM
)
a
(
where
((
rn
=
1
and
merchant_level
>=
4
)
or
merchant_id
in
(
'6329571003697540960'
))
SELECT
sub_id
,
REGEXP_REPLACE
(
SUBSTR
(
call_time
,
0
,
10
),
'-'
,
''
)
as
partition_date
and
merchant_id
not
in
(
'6385685250516781117'
)
--去除和增加是为了和王妍的线索通数据保持一致
FROM
tl
.
tl_gm_sl_ali_virtual_phone_call_detail
--通话记录表,call_type呼叫类型
)
b
WHERE
partition_day
=
regexp_replace
(
date_sub
(
current_date
,
1
),
'-'
,
''
)
on
t1
.
merchant_id
=
b
.
merchant_id
AND
REGEXP_REPLACE
(
SUBSTR
(
call_time
,
0
,
10
),
'-'
,
''
)
>=
REGEXP_REPLACE
(
trunc
(
date_sub
(
current_date
(),
1
),
'MM'
),
'-'
,
''
)
GROUP
BY
user_id
,
partition_date
AND
REGEXP_REPLACE
(
SUBSTR
(
call_time
,
0
,
10
),
'-'
,
''
)
<=
regexp_replace
(
date_sub
(
current_date
(),
1
),
'-'
,
''
)
)
t12
and
start_time
>
call_time
ON
a
.
partition_date
=
t12
.
partition_date
and
a
.
user_id
=
t12
.
user_id
and
unix_timestamp
(
substr
(
start_time
,
1
,
19
))
+
30
<=
unix_timestamp
(
substr
(
release_time
,
1
,
19
))
LEFT
JOIN
)
a
(
---拨打有效电话线索
LEFT
JOIN
SELECT
partition_date
,
user_id
(
,
count
(
1
)
as
valid_call_num
SELECT
id
,
sub_id
FROM
FROM
tl
.
tl_gm_sl_ali_virtual_phone_binding
--阿里记录表
(
WHERE
partition_day
=
regexp_replace
(
date_sub
(
current_date
,
1
),
'-'
,
''
)
SELECT
user_id
,
merchant_id
,
regexp_replace
(
SUBSTR
(
a
.
partition_date
,
1
,
6
),
'-'
,
''
)
AS
CALL_MONTH
,
)
b
MIN
(
partition_date
)
as
partition_date
,
ON
a
.
sub_id
=
b
.
sub_id
1
as
call_num
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
,
REGEXP_REPLACE
(
SUBSTR
(
created_time
,
1
,
10
),
'-'
,
''
)
as
partition_date
FROM
tl
.
tl_gm_sl_lead_task
--线索任务表(用户点击授权后记入该表)
WHERE
partition_day
>=
REGEXP_REPLACE
(
trunc
(
date_sub
(
current_date
(),
1
),
'MM'
),
'-'
,
''
)
AND
partition_day
<=
regexp_replace
(
date_sub
(
current_date
(),
1
),
'-'
,
''
)
AND
source
=
'2'
--用户行为电话授权
group
by
id
,
user_id
,
merchant_id
,
created_time
)
e
ON
d
.
lead_task_id
=
e
.
id
join
(
SELECT
partition_date
,
cl_id
,
user_id
FROM
online
.
bl_hdfs_maidian_updates
where
partition_date
>=
REGEXP_REPLACE
(
trunc
(
date_sub
(
current_date
(),
1
),
'MM'
),
'-'
,
''
)
AND
partition_date
<=
regexp_replace
(
date_sub
(
current_date
,
1
),
'-'
,
''
)
and
params
[
'popup_name'
]
=
'bargain_phone'
and
page_name
=
'ai_plan_list'
and
params
[
'button_name'
]
in
(
'confirm'
)
and
action
=
'on_click_button'
and
int
(
split
(
app_version
,
'
\\
.'
)[
1
])
>=
31
)
ai
on
e
.
user_id
=
ai
.
user_id
and
e
.
partition_date
=
ai
.
partition_date
GROUP
BY
e
.
user_id
,
e
.
merchant_id
,
regexp_replace
(
SUBSTR
(
a
.
partition_date
,
1
,
6
),
'-'
,
''
)
)
t1
GROUP
BY
user_id
,
partition_date
)
t9_v
ON
t3
.
partition_date
=
t9_v
.
partition_date
and
t3
.
user_id
=
t9_v
.
user_id
LEFT
JOIN
(
---拨打电话线索
SELECT
partition_date
,
user_id
,
count
(
1
)
as
call_num
FROM
FROM
(
(
SELECT
sub_id
,
REGEXP_REPLACE
(
SUBSTR
(
call_time
,
0
,
10
),
'-'
,
''
)
as
partition_date
SELECT
user_id
,
merchant_id
,
regexp_replace
(
SUBSTR
(
a
.
partition_date
,
1
,
6
),
'-'
,
''
)
AS
CALL_MONTH
,
FROM
tl
.
tl_gm_sl_ali_virtual_phone_call_detail
--通话记录表,call_type呼叫类型
MIN
(
partition_date
)
as
partition_date
,
WHERE
partition_day
=
regexp_replace
(
date_sub
(
current_date
,
1
),
'-'
,
''
)
1
as
call_num
AND
REGEXP_REPLACE
(
SUBSTR
(
call_time
,
0
,
10
),
'-'
,
''
)
>=
REGEXP_REPLACE
(
trunc
(
date_sub
(
current_date
(),
1
),
'MM'
),
'-'
,
''
)
FROM
AND
REGEXP_REPLACE
(
SUBSTR
(
call_time
,
0
,
10
),
'-'
,
''
)
<=
regexp_replace
(
date_sub
(
current_date
(),
1
),
'-'
,
''
)
(
and
start_time
>
call_time
SELECT
sub_id
,
REGEXP_REPLACE
(
SUBSTR
(
call_time
,
0
,
10
),
'-'
,
''
)
as
partition_date
and
unix_timestamp
(
substr
(
start_time
,
1
,
19
))
+
30
<=
unix_timestamp
(
substr
(
release_time
,
1
,
19
))
FROM
tl
.
tl_gm_sl_ali_virtual_phone_call_detail
--通话记录表,call_type呼叫类型
)
a
WHERE
partition_day
=
regexp_replace
(
date_sub
(
current_date
,
1
),
'-'
,
''
)
LEFT
JOIN
AND
REGEXP_REPLACE
(
SUBSTR
(
call_time
,
0
,
10
),
'-'
,
''
)
>=
REGEXP_REPLACE
(
trunc
(
date_sub
(
current_date
(),
1
),
'MM'
),
'-'
,
''
)
AND
REGEXP_REPLACE
(
SUBSTR
(
call_time
,
0
,
10
),
'-'
,
''
)
<=
regexp_replace
(
date_sub
(
current_date
(),
1
),
'-'
,
''
)
and
start_time
>
call_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'
--用户行为电话授权
)
e
ON
d
.
lead_task_id
=
e
.
id
GROUP
BY
user_id
,
merchant_id
,
regexp_replace
(
SUBSTR
(
a
.
partition_date
,
1
,
6
),
'-'
,
''
)
)
t1
join
(
(
SELECT
id
,
sub_id
SELECT
distinct
merchant_id
FROM
tl
.
tl_gm_sl_ali_virtual_phone_binding
--阿里记录表
FROM
WHERE
partition_day
=
regexp_replace
(
date_sub
(
current_date
,
1
),
'-'
,
''
)
(
SELECT
merchant_id
,
merchant_level
,
row_number
()
over
(
partition
by
merchant_id
order
by
data_month
desc
)
as
rn
FROM
online
.
al_business_merchant_grade_day_repo
where
partition_date
=
regexp_replace
(
date_sub
(
current_date
,
1
),
'-'
,
''
)
)
a
where
((
rn
=
1
and
merchant_level
>=
4
)
or
merchant_id
in
(
'6329571003697540960'
))
and
merchant_id
not
in
(
'6385685250516781117'
)
--去除和增加是为了和王妍的线索通数据保持一致
)
b
)
b
ON
a
.
sub_id
=
b
.
sub_id
on
t1
.
merchant_id
=
b
.
merchant_id
LEFT
JOIN
GROUP
BY
user_id
,
partition_date
(
)
t12
SELECT
id
,
platform_binding_id
ON
t3
.
partition_date
=
t12
.
partition_date
and
t3
.
user_id
=
t12
.
user_id
FROM
tl
.
tl_gm_sl_virtual_phone_binding
LEFT
JOIN
WHERE
partition_day
=
regexp_replace
(
date_sub
(
current_date
,
1
),
'-'
,
''
)
(
---拨打有效电话线索
)
c
SELECT
partition_date
,
user_id
ON
b
.
id
=
c
.
platform_binding_id
,
count
(
1
)
as
valid_call_num
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'
--用户行为电话授权
)
e
ON
d
.
lead_task_id
=
e
.
id
GROUP
BY
user_id
,
merchant_id
,
regexp_replace
(
SUBSTR
(
a
.
partition_date
,
1
,
6
),
'-'
,
''
)
)
t1
join
(
SELECT
distinct
merchant_id
FROM
FROM
(
(
SELECT
merchant_id
,
merchant_level
SELECT
user_id
,
merchant_id
,
regexp_replace
(
SUBSTR
(
a
.
partition_date
,
1
,
6
),
'-'
,
''
)
AS
CALL_MONTH
,
,
row_number
()
over
(
partition
by
merchant_id
order
by
data_month
desc
)
as
rn
MIN
(
partition_date
)
as
partition_date
,
FROM
online
.
al_business_merchant_grade_day_repo
1
as
call_num
where
partition_date
=
regexp_replace
(
date_sub
(
current_date
,
1
),
'-'
,
''
)
FROM
)
a
(
where
((
rn
=
1
and
merchant_level
>=
4
)
or
merchant_id
in
(
'6329571003697540960'
))
SELECT
sub_id
,
REGEXP_REPLACE
(
SUBSTR
(
call_time
,
0
,
10
),
'-'
,
''
)
as
partition_date
and
merchant_id
not
in
(
'6385685250516781117'
)
--去除和增加是为了和王妍的线索通数据保持一致
FROM
tl
.
tl_gm_sl_ali_virtual_phone_call_detail
--通话记录表,call_type呼叫类型
)
b
WHERE
partition_day
=
regexp_replace
(
date_sub
(
current_date
,
1
),
'-'
,
''
)
on
t1
.
merchant_id
=
b
.
merchant_id
AND
REGEXP_REPLACE
(
SUBSTR
(
call_time
,
0
,
10
),
'-'
,
''
)
>=
REGEXP_REPLACE
(
trunc
(
date_sub
(
current_date
(),
1
),
'MM'
),
'-'
,
''
)
GROUP
BY
user_id
,
partition_date
AND
REGEXP_REPLACE
(
SUBSTR
(
call_time
,
0
,
10
),
'-'
,
''
)
<=
regexp_replace
(
date_sub
(
current_date
(),
1
),
'-'
,
''
)
)
t12_v
and
start_time
>
call_time
ON
a
.
partition_date
=
t12_v
.
partition_date
and
a
.
user_id
=
t12_v
.
user_id
and
unix_timestamp
(
substr
(
start_time
,
1
,
19
))
+
30
<=
unix_timestamp
(
substr
(
release_time
,
1
,
19
))
group
by
mas
.
partition_date
,
device_os_type
,
active_type
,
grey_type
)
a
order
by
mas
.
partition_date
desc
,
device_os_type
,
active_type
,
grey_type
LEFT
JOIN
\ No newline at end of file
(
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'
--用户行为电话授权
)
e
ON
d
.
lead_task_id
=
e
.
id
GROUP
BY
user_id
,
merchant_id
,
regexp_replace
(
SUBSTR
(
a
.
partition_date
,
1
,
6
),
'-'
,
''
)
)
t1
join
(
SELECT
distinct
merchant_id
FROM
(
SELECT
merchant_id
,
merchant_level
,
row_number
()
over
(
partition
by
merchant_id
order
by
data_month
desc
)
as
rn
FROM
online
.
al_business_merchant_grade_day_repo
where
partition_date
=
regexp_replace
(
date_sub
(
current_date
,
1
),
'-'
,
''
)
)
a
where
((
rn
=
1
and
merchant_level
>=
4
)
or
merchant_id
in
(
'6329571003697540960'
))
and
merchant_id
not
in
(
'6385685250516781117'
)
--去除和增加是为了和王妍的线索通数据保持一致
)
b
on
t1
.
merchant_id
=
b
.
merchant_id
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
)
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
;
pm/clue_daily/job/clue_daily.zip
View file @
e6e2a254
No preview for this file type
pm/clue_daily/job/step1_13.job
0 → 100644
View file @
e6e2a254
#step1_13.job
type=command
command=sh /home/bi/bi-report/lib/shell/waitsuccess.sh hive ml mid_ml_c_ct_dv_device_inc_d
\ No newline at end of file
pm/clue_daily/job/step1_4.job
View file @
e6e2a254
#step1_3.job
#step1_3.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 ml ml_c_ct_ui_user_dimen_inc_d
\ No newline at end of file
\ No newline at end of file
pm/clue_daily/report/clue_daily.sql
View file @
e6e2a254
SELECT
mas
.
partition_date
`日期`
SELECT
day_id
`日期`
,
device_os_type
`系统`
,
device_os_type
`系统`
,
active_type
`新老`
,
active_type
`新老`
,
grey_type
`是否灰度`
,
grey_type
`是否灰度`
...
@@ -48,4 +48,5 @@ SELECT mas.partition_date `日期`
...
@@ -48,4 +48,5 @@ SELECT mas.partition_date `日期`
,
valid_call_dev_qa
as
`有效电话线索设备数-需求自测`
,
valid_call_dev_qa
as
`有效电话线索设备数-需求自测`
,
valid_call_num_qa
as
`有效电话线索人次-需求自测`
,
valid_call_num_qa
as
`有效电话线索人次-需求自测`
FROM
pm
.
tl_pm_userclue_d
FROM
pm
.
tl_pm_userclue_d
where
partition_day
=
regexp_replace
(
date_sub
(
current_date
,
1
),
'-'
,
''
)
where
partition_day
in
(
'20200901'
,
'202001001'
,
'20201101'
,
'20201201'
,
'20210101'
,
regexp_replace
(
date_sub
(
current_date
,
1
),
'-'
,
''
))
\ No newline at end of file
order
by
`日期`
,
`系统`
,
`新老`
,
`是否灰度`
pm/search_related/etl/search_related.sql
View file @
e6e2a254
...
@@ -33,7 +33,8 @@ FROM
...
@@ -33,7 +33,8 @@ FROM
and
page_name
in
(
'diary_detail'
,
'topic_detail'
,
'post_detail'
,
'user_post_detail'
and
page_name
in
(
'diary_detail'
,
'topic_detail'
,
'post_detail'
,
'user_post_detail'
,
'doctor_post_detail'
,
'question_detail'
,
'answer_detail'
,
'question_answer_detail'
)
then
'内容详情页搜索框'
,
'doctor_post_detail'
,
'question_detail'
,
'answer_detail'
,
'question_answer_detail'
)
then
'内容详情页搜索框'
when
action
=
'详情页高亮词'
then
'详情页高亮词搜索'
when
action
=
'详情页高亮词'
then
'详情页高亮词搜索'
when
action
=
'大家都在看'
then
'首页feed大家都在看'
when
action
=
'新首页-大家都在看'
then
'新首页-大家都在看'
when
action
=
'旧首页-大家都在看'
then
'旧首页-大家都在看'
when
action
=
'热搜词'
then
'美购首页热搜词'
else
null
end
as
search_entrance
when
action
=
'热搜词'
then
'美购首页热搜词'
else
null
end
as
search_entrance
,
count
(
cl_id
)
as
search_pv
,
count
(
cl_id
)
as
search_pv
,
count
(
distinct
cl_id
)
as
search_uv
,
count
(
distinct
cl_id
)
as
search_uv
...
@@ -64,7 +65,7 @@ FROM
...
@@ -64,7 +65,7 @@ FROM
union
all
union
all
SELECT
partition_date
,
cl_id
,
null
as
page_name
,
'大家都在看'
as
action
,
null
as
referrer_link
SELECT
partition_date
,
cl_id
,
null
as
page_name
,
'
新首页-
大家都在看'
as
action
,
null
as
referrer_link
FROM
online
.
bl_hdfs_maidian_updates
FROM
online
.
bl_hdfs_maidian_updates
where
partition_date
=
regexp_replace
(
DATE_SUB
(
current_date
,
1
)
,
'-'
,
''
)
where
partition_date
=
regexp_replace
(
DATE_SUB
(
current_date
,
1
)
,
'-'
,
''
)
AND
action
=
'on_click_card'
AND
action
=
'on_click_card'
...
@@ -73,6 +74,15 @@ FROM
...
@@ -73,6 +74,15 @@ FROM
AND
params
[
'card_type'
]
=
'search_word'
AND
params
[
'card_type'
]
=
'search_word'
--AND page_name='home' android的page_name为空
--AND page_name='home' android的page_name为空
union
all
SELECT
partition_date
,
cl_id
,
page_name
,
'旧首页-大家都在看'
as
action
,
null
as
referrer_link
FROM
online
.
bl_hdfs_maidian_updates
where
partition_date
>=
'20200801'
and
partition_date
<=
regexp_replace
(
DATE_SUB
(
current_date
,
1
)
,
'-'
,
''
)
AND
action
=
'do_search'
and
params
[
'input_type'
]
=
'everyone_watch'
and
params
[
'tab'
]
=
'精选'
and
page_name
=
'home'
union
all
union
all
SELECT
partition_date
,
cl_id
,
page_name
,
'热搜词'
as
action
,
null
as
referrer_link
SELECT
partition_date
,
cl_id
,
page_name
,
'热搜词'
as
action
,
null
as
referrer_link
...
@@ -104,7 +114,8 @@ FROM
...
@@ -104,7 +114,8 @@ FROM
and
page_name
in
(
'diary_detail'
,
'topic_detail'
,
'post_detail'
,
'user_post_detail'
and
page_name
in
(
'diary_detail'
,
'topic_detail'
,
'post_detail'
,
'user_post_detail'
,
'doctor_post_detail'
,
'question_detail'
,
'answer_detail'
,
'question_answer_detail'
)
then
'内容详情页搜索框'
,
'doctor_post_detail'
,
'question_detail'
,
'answer_detail'
,
'question_answer_detail'
)
then
'内容详情页搜索框'
when
action
=
'详情页高亮词'
then
'详情页高亮词搜索'
when
action
=
'详情页高亮词'
then
'详情页高亮词搜索'
when
action
=
'大家都在看'
then
'首页feed大家都在看'
when
action
=
'新首页-大家都在看'
then
'新首页-大家都在看'
when
action
=
'旧首页-大家都在看'
then
'旧首页-大家都在看'
when
action
=
'热搜词'
then
'美购首页热搜词'
else
null
end
when
action
=
'热搜词'
then
'美购首页热搜词'
else
null
end
having
search_entrance
is
not
null
having
search_entrance
is
not
null
)
t
)
t
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment