Ciao a tutti!
Qualcuno ha mai scritto una query per Data Explorer per ottenere il conteggio totale dei membri per mese, con un risultato simile a questo?
Ciao a tutti!
Qualcuno ha mai scritto una query per Data Explorer per ottenere il conteggio totale dei membri per mese, con un risultato simile a questo?
C’è qualche genio di Data Explorer qui? ![]()
Immagino tu ti riferisca a qualcosa di simile?
select date_part('year', created_at) as anno,
date_part('month', created_at) as mese,
count(*) as "count"
from users
group by date_part('year', created_at), date_part('month', created_at)
order by date_part('year', created_at) asc,
date_part('month', created_at)
Quasi, ma mi sta restituendo il numero di utenti creati ogni mese, mentre intendevo il numero complessivo di utenti che la nostra piattaforma ha in un determinato mese. Quindi, ad esempio, se a marzo erano 1000 e ad aprile ne abbiamo aggiunti 20, il totale per aprile sarĂ 1020.
Spero che possa essere utile.
WITH data_month AS (
SELECT
date_part('year', created_at) AS year,
date_part('month', created_at) AS month,
COUNT(*) AS "new_users_month"
FROM users
GROUP BY date_part('year', created_at), date_part('month', created_at)
ORDER BY date_part('year', created_at) ASC, date_part('month', created_at)
)
SELECT
year,
month,
new_users_month,
SUM(new_users_month) over (ORDER BY year, month rows between unbounded preceding AND current row) AS total
FROM data_month ORDER BY year, month
| year | month | new_users_month | total |
|---|---|---|---|
| 2020 | 2 | 50 | 50 |
| 2020 | 3 | 100 | 150 |
| 2020 | 4 | 50 | 200 |
Perfetto, grazie per l’aiuto!
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.