feyikemiKaia: Cohort Retention copy
Updated 2025-02-25
99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
›
⌄
-- forked from i_dan / Kaia: Cohort Retention @ https://flipsidecrypto.xyz/i_dan/q/4fdM_hjWNEIe/kaia-cohort-retention
WITH cohorts AS (
SELECT
from_address
, MIN(DATEADD(MONTH,
CASE
WHEN MONTH(block_timestamp) <= 6 THEN 0
ELSE 6
END,
DATE_TRUNC('YEAR', block_timestamp)
)) AS cohort_semester
FROM kaia.core.fact_transactions
GROUP BY 1
),
semester_activity AS (
SELECT
from_address
, DATEADD(MONTH,
CASE
WHEN MONTH(block_timestamp) <= 6 THEN 0
ELSE 6
END,
DATE_TRUNC('YEAR', block_timestamp)
) AS activity_semester
FROM kaia.core.fact_transactions
),
cohort_retention AS (
SELECT
c.cohort_semester
, w.activity_semester
, COUNT(DISTINCT c.from_address) AS retained_users
FROM cohorts c
JOIN semester_activity w
ON c.from_address = w.from_address
GROUP BY 1, 2
QueryRunArchived: QueryRun has been archived