angelnathExercise on Aggregate with CTE
Updated 2025-02-15Copy Reference Fork
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
›
⌄
-- Exercise on Aggregate with CTE forked copy @ https://flipsidecrypto.xyz/studio/queries/827b2277-7404-47cc-8f31-55e7e2ca5d13
--Create a query to analyze DEX swap activity on Ethereum using ethereum.defi.ez_dex_swaps. Find:
--Daily swap statistics for each DEX (platform)
--Only include days with total volume > $1 million
--Only look at the last 30 days of data
--Show statistics for number of swaps, unique traders, total volume, average swap size
--Order by daily volume
WITH vol_data AS (
SELECT
DATE_TRUNC('day', block_timestamp) as date,
--DATE_TRUNC('month', block_timestamp) as month,
platform AS dex,
Origin_from_address AS user,
COALESCE(AMOUNT_IN_USD, amount_out_usd) AS Total_volume
FROM
ethereum.defi.ez_dex_swaps
WHERE
block_timestamp >= DATEADD(day, -30, Current_date())
--WHERE block_timestamp >= DATEADD(month, -12, Current_date())
)
SELECT
date,
FROM
vol_data
WHERE dex like '%v3' --new addition and tweaking from the office hour
GROUP BY
date,
QueryRunArchived: QueryRun has been archived