tannylimited-cyan
Updated 2024-11-07
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
›
⌄
-- Step 1: Identify unique users and their first interaction month
WITH initial_users AS (
SELECT DISTINCT sender AS user_address,
DATE_TRUNC('month', block_timestamp) AS first_month
FROM ethereum.uniswapv3.ez_swaps -- Adjust to the correct table name if different
),
-- Step 2: Track user interactions for each month
monthly_interactions AS (
SELECT sender AS user_address,
DATE_TRUNC('month', block_timestamp) AS month
FROM ethereum.uniswapv3.ez_swaps
)
-- Step 3: Calculate monthly retention
SELECT iu.first_month,
mi.month,
COUNT(DISTINCT mi.user_address) AS returning_users
FROM initial_users iu
JOIN monthly_interactions mi
ON iu.user_address = mi.user_address
AND mi.month >= iu.first_month -- Ensure we’re only tracking users from their first month onward
GROUP BY iu.first_month, mi.month
ORDER BY iu.first_month, mi.month;
QueryRunArchived: QueryRun has been archived