These queries give a breakdown of how many new user accounts have been created within the timeframe, excluding staged and non-activated accounts. The totals are broken down by number of signups each week/month/year, a running total for the time period selected, and a total number to date which includes all previous signups.
NB: If a user is deleted their records no longer appear in the database and will therefore no longer be included in the query results. This can lead to variations when comparing recent runs against previous ones.
Weekly Signups
-- [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
Week Begin |
Weekly Signups |
Running Total |
Sum Total |
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 |
Monthly Signups
-- [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
Month |
Monthly Signups |
Running Total |
Sum Total |
June 2023 |
596 |
596 |
44790 |
July 2023 |
517 |
1113 |
45307 |
August 2023 |
583 |
1696 |
45890 |
September 2023 |
102 |
1798 |
46005 |
Yearly Signups
-- [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
Year |
Yearly Signups |
Running Total |
Sum Total |
2019 |
3590 |
3590 |
23135 |
2020 |
4258 |
7848 |
27393 |
2021 |
5908 |
13756 |
33301 |
2022 |
7889 |
21645 |
41190 |
2023 |
4815 |
26460 |
46005 |