datavortexnew vs returning traders
Updated 2024-10-31
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
›
⌄
WITH UserSwaps AS (
SELECT
tx_id,
trader,
DATE_TRUNC('month', block_timestamp) AS swap_month,
amount_in_usd,
ROW_NUMBER() OVER (PARTITION BY trader ORDER BY block_timestamp) AS swap_rank
FROM
flow.defi.ez_dex_swaps
),
MonthlyUserActivity AS (
SELECT
swap_month,
trader,
CASE
WHEN swap_rank = 1 THEN 'new_user'
ELSE 'returning_user'
END AS user_type,
amount_in_usd
FROM
UserSwaps
)
SELECT
swap_month,
user_type,
COUNT(DISTINCT trader) AS user_count,
SUM(amount_in_usd) AS total_volume
FROM
MonthlyUserActivity
GROUP BY
swap_month, user_type
ORDER BY
swap_month, user_type;
QueryRunArchived: QueryRun has been archived