여러분 안녕하세요!
누군가 월별 전체 회원 수를 가져오는 Data Explorer 쿼리를 작성해 본 적이 있으신가요? 결과가 다음과 같은 형태여야 합니다:
여기 Data Explorer에 정통한 분이 계신가요? ![]()
아마도 이런 식으로 말씀하시는 거죠?
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)
꽤 근접한 답변인데, 현재는 매월 생성된 사용자 수를 보여주고 있어요. 제가 의도했던 것은 특정 월에 플랫폼에 존재하는 전체 사용자 수였어요. 예를 들어, 3월에 1,000명이었고 4월에 20명이 새로 가입했다면, 4월의 전체 사용자 수는 1,020명이 되는 거죠.
도움이 되길 바랍니다.
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 |
완벽합니다! 도움 주셔서 감사합니다!