常用SQL示例
APP主题包
如何计算某日新增用户数?
--SQL简单支持数据量少的场景
select ds
,count(distinct umid) as dau
from ump_cdm.dwd_ump_log_uapp_launch_di
where ds >= '20220718'
and ds <= '20220720'
and app_key = '6010183ea1475b0f74bdc3c7'
group by ds
order by ds
;
--对count distinct优化,提升查询效率
select ds
,sum(1) as dau
from (
select ds
,umid
from ump_cdm.dwd_ump_log_uapp_launch_di
where ds >= '20220718'
and ds <= '20220720'
and app_key = '6010183ea1475b0f74bdc3c7'
group by ds
,umid
) t
group by ds
order by ds
;如何计算某日新增用户数?
select ds
,count(distinct umid) as new
from ump_cdm.dwd_ump_log_uapp_launch_di
where ds >= '20220718'
and ds <= '20220720'
and is_new_install = '1'
and app_key = '6010183ea1475b0f74bdc3c7'
group by ds
order by ds
;如何计算某日启动次数?
select ds
,sum(session_start) as launch
from ump_cdm.dwd_ump_log_uapp_launch_di
where ds >= '20220718'
and ds <= '20220720'
and app_key = '6010183ea1475b0f74bdc3c7'
group by ds
order by ds
;