select
round(sum(case when '2020-11-20' between begin_date and end_date then pay_amount/(datediff(end_date,begin_date)) else 0 end),2) as total_daily_income
from bilibili_m1
with a as(
select
usr_id,
date_format(login_time,'%Y-%m-%d') as login_time
from user_login_log
where datediff(current_date(),login_time)<=30
group by usr_id, date_format(login_time,'%Y-%m-%d')),
b as(
select
usr_id,
login_time,
date_sub(login_time,interval row_number()over(partition by usr_id order by login_time) day) as diff
from a)
select
usr_id,
min(login_time) as start_date,
max(login_time) as end_date,
count(*) as consecutive_days
from b
group by usr_id,diff
having consecutive_days >=3
order by usr_id,
start_date
with a as(
select
usr_id,
date_format(login_time,'%Y-%m-%d') as login_time
from user_login_log
where datediff(current_date(),login_time)<=29
group by usr_id,login_time),
b as(
select
usr_id,
login_time,
date_sub(login_time,interval row_number()over(partition by usr_id order by login_time) day) as diff
from a)
select
usr_id,
min(login_time) as start_date,
max(login_time) as end_date,
count(*) as consecutive_days
from b
group by usr_id,diff
having consecutive_days >=3
order by usr_id,
start_date
with a as(
select
usr_id,
date_format(login_time,'%Y-%m-%d') as login_time
from user_login_log
where datediff(current_date(),login_time)<=30
group by usr_id,login_time),
b as(
select
usr_id,
login_time,
date_sub(login_time,interval row_number()over(partition by usr_id order by login_time) day) as diff
from a)
select
usr_id,
min(login_time) as start_date,
max(login_time) as end_date,
count(*) as consecutive_days
from b
group by usr_id,diff
having consecutive_days >=3
order by usr_id desc,
start_date
with a as(
select
usr_id,
date_format(login_time,'%Y-%m-%d') as login_time
from user_login_log
where datediff(current_date(),login_time)<=30
group by usr_id,login_time),
b as(
select
usr_id,
login_time,
date_sub(login_time,interval row_number()over(partition by usr_id order by login_time) day) as diff
from a)
select
usr_id,
min(login_time) as start_date,
max(login_time) as end_date,
count(*) as consecutive_days
from b
group by usr_id,diff
having consecutive_days >=3
order by usr_id,
start_date
with a as(
select
usr_id,
date_format(login_time,'%Y-%m-%d') as login_time
from user_login_log
where datediff(current_date(),login_time)<=30
group by usr_id,login_time),
b as(
select
usr_id,
login_time,
date_sub(login_time,interval row_number()over(partition by usr_id order by login_time) day) as diff
from a)
select
usr_id,
min(login_time) as start_date,
max(login_time) as end_date,
count(*) as consecutive_days
from b
group by usr_id,diff
having consecutive_days >=3
select
gd_typ,
count(distinct cust_uid) as buyer_count
from xhs_pchs_rcd a
join gd_inf b
on a.mch_id = b.gd_id
group by gd_typ
order by buyer_count desc
limit 1
select
date_format(enter_time,'%h') as hour_entered,
count(distinct usr_id) as enter_count
from ks_live_t1
group by date_format(enter_time,'%h')
order by hour_entered desc
select
date_format(enter_time,'%h') as hour_entered,
count(distinct usr_id) as enter_count
from ks_live_t1
group by date_format(enter_time,'%h')
order by hour_entered
select
date_format(enter_time,'%h') as hour_entered,
count(*) as enter_count
from ks_live_t1
group by date_format(enter_time,'%h')
order by hour_entered
select
*
from
(select
date_format(order_time,'%Y-%m-%d') as order_date,
goods_id,
sum(order_gmv) as total_gmv,
row_number()over(partition by date_format(order_time,'%Y-%m-%d') order by sum(order_gmv)) as ranking
from order_info
where date_format(order_time,'%Y-%m') = '2024-10'
group by date_format(order_time,'%Y-%m-%d'),goods_id) a
where ranking <=3
select
count(distinct usr_id)
from user_login_log
where date_format(login_time,'%Y-%m-%d') <='2024-10-01'
and usr_id not in(
select
distinct
usr_id
from user_login_log
where date_format(login_time,'%Y-%m-%d') >'2024-10-01'
)
select
distinct
usr_id
from user_login_log
where date_format(login_time,'%Y-%m-%d') <='2024-10-01'
and usr_id not in(
select
distinct
usr_id
from user_login_log
where date_format(login_time,'%Y-%m-%d') >'2024-10-01'
)