Data Explorerを使用して月ごとの全体的なメンバー数を取得する

こんにちは、皆さん!

月ごとのメンバー総数を取得する Data Explorer クエリを作成したことはありますか?以下のような結果が得られるものです。

Data Explorer の天才さんはいますか? :smiley:

おそらく、このようなことをおっしゃりたいのでしょうか?

select date_part('year', created_at) as year, 
date_part('month', created_at) as month,
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)
「いいね!」 2

かなり近いですが、現在は「毎月作成されたユーザー数」が表示されています。私が意図していたのは、「特定月のプラットフォーム全体のユーザー総数」です。例えば、3 月が 1000 人で、4 月に 20 人増えた場合、4 月の総数は 1020 人となります。

「いいね!」 1

お役に立てれば幸いです。

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
「いいね!」 4

完璧です!お手伝いありがとうございます!

「いいね!」 2

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.