-- 1. 时间粒度是小时
select
distinct uid
from(
select
substr(login_time,1,13),
uid,
count(1) as icount
from
t_login_record
where
to_date(login_time) = '2018-07-01'
group by
substr(login_time,1,13),
uid
)t
where
icount > 10 ;
-- 2. 以分钟为粒度
select distinct
a.uid
from(
select
a.uid,
a.login_time,
count(b.uid) as icount
from(
select
concat(substr(login_time,1,16),'-00') as login_time,
uid
from
t_login_record
where
to_date(login_time) = '2018-07-01'
)a
left join(
select
concat(substr(login_time,1,16),'-00') as login_time,,
uid
from
t_login_record
where
to_date(login_time) = '2018-07-01'
)b
on
a.uid = b.uid
and
unix_timestamp(a.login_time) - unix_timestamp(b.login_time) between -3600 and -1
group by
a.uid,a.login_time
)t
where
icount>10;
-- 每天注册用户总量及占所有用户比例,
select
a.reg_date,
a.platform,
a.iregcount,
case when a.iregcount is null then 0 else a.iregcount end * 100 / b.iregcount as iregpercent
from(
select
to_date(reg_time) as reg_date,
platform,
count(distinct uid) as iregcount
from
t_user
where
to_date(reg_time) between '2018-01-01' and '2018-01-31'
group by
to_date(reg_time),
platform
union all
select
to_date(reg_time) as reg_date,
'all platform' as platform,
count(distinct uid) as iregcount
from
t_user
where
to_date(reg_time) between '2018-01-01' and '2018-01-31'
group by
to_date(reg_time)
) a
left join(
select
count(distinct uid) as iregcount
from
t_user
group by
platform
) b
on
1= 1;
-- 各平台用户按周同比增长
select
a.reg_week,
a.platform,
case when b.iregcount is null then null else
round(100 * (b.iregcount - a.iregcount) / a.iregcount ,2) as ireg_increase_precent
from (
select
weekofyear(reg_time) as reg_week,
platform,
count(distinct uid) as iregcount
from
t_user
where
to_date(reg_time) between '2018-01-01' and '2018-01-31'
group by
weekofyear(reg_time) as reg_week,
platform
) a
left join (
select
weekofyear(reg_time) as reg_week,
platform,
count(distinct uid) as iregcount
from
t_user
where
to_date(reg_time) between '2018-01-01' and '2018-01-31'
group by
weekofyear(reg_time) as reg_week,
platform
) b
on
a.platform = b.platform
and
a.reg_week = b.reg_week + 1
;
select
uid,
sum(case when datediff(CURRENT_DATE,to_date(ordr_time)) = 1 then goods_num else 0 end),
sum(case when datediff(CURRENT_DATE,to_date(ordr_time)) <= 7 then goods_num else 0 end),
sum(case when datediff(CURRENT_DATE,to_date(ordr_time)) <= 30 then goods_num else 0 end),
sum(goods_num)
from
t_trade_records
where
datediff(CURRENT_DATE,to_date(ordr_time)) <= 180
group by
uid