Поменял форму и названия и исправил NULL
This commit is contained in:
@@ -15,22 +15,23 @@
|
||||
Нужно найти ежемесячное процентное изменение месячной аудитории активных пользователей.
|
||||
'''
|
||||
|
||||
with cte1 as (
|
||||
select count(distinct(user_id)) as mau,
|
||||
with monthly_users as (
|
||||
select count(distinct(user_id)) as active_users,
|
||||
date_trunc('month', date) as month
|
||||
from abakhytbekuly.users
|
||||
group by date_trunc('month', date)
|
||||
),
|
||||
cte2 as (
|
||||
select mau,
|
||||
change as (
|
||||
select active_users,
|
||||
month,
|
||||
lag(mau) over(order by month) as prev_mau
|
||||
from cte1
|
||||
lag(active_users) over(order by month) as prev_mau
|
||||
from monthly_users
|
||||
)
|
||||
select mau,
|
||||
select active_users,
|
||||
month,
|
||||
prev_mau,
|
||||
100.0 * (mau - prev_mau) / prev_mau as pct_change
|
||||
from cte2
|
||||
100.0 * (active_users - prev_mau) / prev_mau as pct_change -- тут результат странный типа '-66.666666'
|
||||
from change
|
||||
where prev_mau is not null
|
||||
order by month
|
||||
|
||||
|
||||
Reference in New Issue
Block a user