--用户数据表结构
--yyyymmdd 代表用户测试这句话说的日期 ---dt
--nlu_utterance 代表用户说的某句话 ---platform
--svicd 代表用户的手机码 ------ mid
--sf_user_data--代表用户说某句话的所有log
--sf_first_user_data 所有的新增用户
--表1、记录用户首次使用的日期
drop table if exists cincinnati_com.sf_first_user_data
create table if not exists cincinnati_com.sf_first_user_data as
--SELECT *, Row_Number() OVER (partition by deptid ORDER BY salary desc) rank FROM employee
select * ,Row_Number () OVER (partition by table1.svicd ORDER BY table1.uid esc) rank from(
select svicd,
uid,
nlu_utterance
from kpi_team.bixby_daily_report
where language = 'zh-CN'
and yyyymmdd between 20180208 and 20180228
and nlu_utterance like '%XX%'
) as table1
where rank = 1
------------------------------------------------------
--表2、创建该表让新增用户时间+1 和 sf_user_data 做个inner join ,取 其 的数量 / sf_first_user_data 的数量 为 次日留存率
select
svicd,
uid,
nlu_utterance
from
(select
svicd,
uid,
nlu_utterance,
yyyymmdd
from sf_first_user_data
as table1)
where yyyymmdd = table1.yyyymmdd
--日期增加函数
--date_add(string startdate, int days)
select
date_add('yyyymmdd',1) from test;
insert into report_userinfo
select
xinzeng.platform,
xinzeng.dt,
xinzeng.channel,
xinzeng.cver,
2,
count(distinct cunliu.pcid),
datediff(
from_unixtime(unix_timestamp(cast(cunliu.dt as string),'yyyyMMdd')),
from_unixtime(unix_timestamp(cast(xinzeng.dt as string),'yyyyMMdd'))
)
from
(
select * from user_login_history where type=1
) xinzeng
inner join
(
select
platform,
dt,
channel,
cver,
mid pcid
from log_vvim
where mid is not null and dt=$dt group by platform,dt,channel,cver,mid
) cunliu on
(
xinzeng.platform=cunliu.platform and
xinzeng.channel=cunliu.channel and
xinzeng.cver=cunliu.cver and
xinzeng.pcid=cunliu.pcid
)
where cunliu.dt>xinzeng.dt
group by
xinzeng.platform,xinzeng.dt,xinzeng.channel,xinzeng.cver,
datediff(
from_unixtime(unix_timestamp(cast(cunliu.dt as string),'yyyyMMdd')),
from_unixtime(unix_timestamp(cast(xinzeng.dt as string),'yyyyMMdd'))
);
select retention_sum(xwho_state, 4, 30, 1, 5)
from (
select retention_count(
date_diff('day', from_iso8601_timestamp('2018-02-26'), to_timestamp(day, 'yyyymmdd')), 4, 1, 5,
case when ( day >= '20180226' and day <= '20180301' and standard_event_id = 1311 and standard_app_id=100361 ) and ( day >= '20180227' and day <= '20180331' and standard_event_id = 132678 and standard_app_id=100361 ) then 0
when ( day >= '20180226' and day <= '20180301' and standard_event_id = 1311 and standard_app_id=100361 ) then 1 else -1 end , 1, -1) as xwho_state
from fz_bds.bds_ait_device_event_info_d eventAttr
where
(
(day >= '20180226' and day <= '20180301' and standard_event_id = 1311 and standard_app_id=100361 ) or
(day >= '20180227' and day <= '20180331' and standard_event_id = 132678 and standard_app_id=100361 )
)
group by eventAttr.tmp_id
)