# 주/월/연간 가입 현황

**URL:** https://meta.discourse.org/t/weekly-monthly-yearly-signups/278119
**Category:** Data & reporting
**Tags:** sql-query
**Created:** [9월 7, 2023, 5:24오전 UTC](https://meta.discourse.org/t/weekly-monthly-yearly-signups/278119 "2023-09-07T05:24:18Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [9월 7, 2023, 5:24오전 UTC](https://meta.discourse.org/t/weekly-monthly-yearly-signups/278119/1 "2023-09-07T05:24:18Z")

</div>

> 📝 이 쿼리들은 지정된 기간 동안 생성된 신규 사용자 계정의 수를 보여줍니다. 여기서 스테이징된 계정과 비활성화된 계정은 제외됩니다. 총계는 주/월/년별 가입자 수, 선택된 기간에 대한 누적 합계, 그리고 이전 모든 가입자를 포함한 현재까지의 총 가입자 수로 구분됩니다.
> 
> **참고:** 사용자가 삭제되면 해당 기록이 데이터베이스에서 더 이상 표시되지 않으므로 쿼리 결과에도 포함되지 않습니다. 이로 인해 최근 실행 결과와 이전 실행 결과를 비교할 때 변동이 발생할 수 있습니다.

### 주간 가입자 수

```sql
-- [params]
-- date :start_date
-- date :end_date

WITH weekly_signups AS (

SELECT
    to_char(date_trunc('week', created_at)::date,'YYYY-MM-DD') AS week,
    COUNT(*) AS signups
FROM users
WHERE created_at::date BETWEEN :start_date::date AND :end_date::date
  AND staged = false
  AND active = true
GROUP BY week
),

all_to_date AS (

SELECT COUNT(*) AS previous
FROM users
WHERE created_at::date < :start_date
  AND staged = false
  AND active = true

)

SELECT
    week AS "Week Begin", 
    signups AS "Weekly Signups", 
    SUM(signups::int) OVER (ORDER BY week) AS "Running Total",
    (SUM(signups::int) OVER (ORDER BY week) + previous::int) AS "Sum Total"
FROM weekly_signups, all_to_date
ORDER BY week ASC

```

| 주 시작일 | 주간 가입자 수 | 누적 합계 | 총 합계 |
| --- | --- | --- | --- |
| 2023-07-31 | 98 | 98 | 45418 |
| 2023-08-07 | 141 | 239 | 45559 |
| 2023-08-14 | 129 | 368 | 45688 |
| 2023-08-21 | 126 | 494 | 45814 |
| 2023-08-28 | 138 | 632 | 45952 |
| 2023-09-04 | 53 | 685 | 46005 |

  

### 월간 가입자 수

```sql
-- [params]
-- date :start_date
-- date :end_date

WITH monthly_signups AS (
SELECT
    date_trunc('month', created_at)::date AS month,
    to_char(date_trunc('month', created_at)::date,'Month YYYY') AS month_display,
    COUNT(*) AS signups
FROM users
WHERE created_at::date BETWEEN :start_date::date AND :end_date::date
  AND staged = false
  AND active = true
GROUP BY month, month_display
),

all_to_date AS (
SELECT COUNT(*) AS previous
FROM users
WHERE created_at::date < :start_date
  AND staged = false
  AND active = true
)

SELECT
    month_display AS "Month", 
    signups AS "Monthly Signups", 
    SUM(signups::int) OVER (ORDER BY month) AS "Running Total",
    (SUM(signups::int) OVER (ORDER BY month) + previous::int) AS "Sum Total"
FROM monthly_signups, all_to_date
ORDER BY month

```

| 월 | 월간 가입자 수 | 누적 합계 | 총 합계 |
| --- | --- | --- | --- |
| 2023년 6월 | 596 | 596 | 44790 |
| 2023년 7월 | 517 | 1113 | 45307 |
| 2023년 8월 | 583 | 1696 | 45890 |
| 2023년 9월 | 102 | 1798 | 46005 |

  

### 연간 가입자 수

```sql
-- [params]
-- date :start_date
-- date :end_date

WITH yearly_signups AS (

SELECT
    to_char(date_trunc('year', created_at)::date,'YYYY') AS year,
    COUNT(*) AS signups
FROM users
WHERE created_at::date BETWEEN :start_date::date AND :end_date::date
  AND staged = false
  AND active = true
GROUP BY year
),

all_to_date AS (

SELECT COUNT(*) AS previous
FROM users
WHERE created_at::date < :start_date
  AND staged = false
  AND active = true

)

SELECT
    year AS "Year", 
    signups AS "Yearly Signups", 
    SUM(signups::int) OVER (ORDER BY year) AS "Running Total",
    (SUM(signups::int) OVER (ORDER BY year) + previous::int) AS "Sum Total"
FROM yearly_signups, all_to_date
ORDER BY year ASC

```

| 연도 | 연간 가입자 수 | 누적 합계 | 총 합계 |
| --- | --- | --- | --- |
| 2019 | 3590 | 3590 | 23135 |
| 2020 | 4258 | 7848 | 27393 |
| 2021 | 5908 | 13756 | 33301 |
| 2022 | 7889 | 21645 | 41190 |
| 2023 | 4815 | 26460 | 46005 |

---

<div class="post-metadata">

### Author: ![outofthebox](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/outofthebox/32/83708_2.png) [@outofthebox](https://meta.discourse.org/u/outofthebox)
#### Post date: [1월 20, 2024, 11:31오후 UTC](https://meta.discourse.org/t/weekly-monthly-yearly-signups/278119/3 "2024-01-20T23:31:21Z")

</div>

안녕하세요, 이 기능이 어떻게 작동하는지 이해하는 데 좀 서투른 것 같아 죄송합니다. 날짜가 입력된 예시는 어떤 모습인가요?

---

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [1월 20, 2024, 11:43오후 UTC](https://meta.discourse.org/t/weekly-monthly-yearly-signups/278119/4 "2024-01-20T23:43:39Z")

</div>

무엇을 말씀하시는 건지 잘 모르겠어요? 찾으시는 것이 그거라면, 각 항목 아래에 결과 예시가 있습니다.

---

<div class="post-metadata">

### Author: ![outofthebox](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/outofthebox/32/83708_2.png) [@outofthebox](https://meta.discourse.org/u/outofthebox)
#### Post date: [1월 21, 2024, 12:19오전 UTC](https://meta.discourse.org/t/weekly-monthly-yearly-signups/278119/5 "2024-01-21T00:19:42Z")

</div>

알겠습니다.

제가 시도하고 있는 질문은 이렇습니다: 시작 날짜와 종료 날짜를 코드 어디에, 그리고 어떤 형식으로 입력해야 하는가요?

---

<div class="post-metadata">

### Author: ![Firepup650](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/firepup650/32/465200_2.png) [@Firepup650](https://meta.discourse.org/u/Firepup650)
#### Post date: [1월 21, 2024, 12:26오전 UTC](https://meta.discourse.org/t/weekly-monthly-yearly-signups/278119/6 "2024-01-21T00:26:17Z")

</div>

> [@outofthebox](#):
>
> 코드 어디에 시작일과 종료일을 넣어야 하나요?

넣지 않아도 됩니다. 쿼리를 실행하는 버튼 위에 입력 상자가 자동으로 추가되어야 하기 때문입니다(추가되지 않았다면 저장 후 새로고침하면 나타납니다). 그리고

> [@outofthebox](#):
>
> 어떤 형식으로 작성해야 하나요?

날짜 선택기가 자동으로 나타날 것 같습니다.

---

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [1월 21, 2024, 12:32오전 UTC](https://meta.discourse.org/t/weekly-monthly-yearly-signups/278119/7 "2024-01-21T00:32:24Z")

</div>

아, 네. 페이지를 새로고침할 때까지 첫 번째에는 파라미터 입력 상자가 표시되지 않는 알려진 문제가 있습니다.

날짜 선택기가 아직 충분히 매끄럽지는 않습니다(하지만 잘 되길 바랍니다 🙂 🤞), 하지만 형식에 대해서는 꽤 관대합니다. 제가 직접 사용할 때는 영국식 날짜 형식(예: 21/01/2024)을 사용하지만, 스크린샷 예시를 공유할 때는 더 보편적인 형식인 예: 2024-01-21을 따르려 합니다.

 ![IMG_3563](https://global.discourse-cdn.com/meta/original/4X/5/a/3/5a388af6b0381f191e3e37ac3e415ac8c669a56a.jpeg)

---

<div class="post-metadata">

### Author: ![outofthebox](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/outofthebox/32/83708_2.png) [@outofthebox](https://meta.discourse.org/u/outofthebox)
#### Post date: [1월 21, 2024, 1:25오전 UTC](https://meta.discourse.org/t/weekly-monthly-yearly-signups/278119/8 "2024-01-21T01:25:42Z")

</div>

이제 이해했어요. 감사합니다. 페이지를 새로고침해야 했어요.
