jackguy2023-05-01 07:28 PM copy
Updated 2023-05-09
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 2023-05-01 07:28 PM @ https://flipsidecrypto.xyz/edit/queries/05732257-c9a0-4345-8e44-581212774245
SELECT
median(active_weeks),
avg(active_weeks)
FROM (
SELECT --*,
-- date_trunc('week', block_timestamp) as week,
ORIGIN_FROM_ADDRESS,
count(DISTINCT date_trunc('week', block_timestamp)) as active_weeks ,
--count(DISTINCT ORIGIN_FROM_ADDRESS) as users,
sum(
CASE
when not amount_in_usd is NULL then amount_in_usd
when not amount_out_usd is NULL then amount_out_usd
--when token_price1 is NULL then token_price2 * TOKEN_OUT
--else token_price1 * TOKEN_IN end as tt
else 0 end
) as volume_usd
FROM avalanche.core.ez_dex_swaps
LEFT outer join (
SELECT
date_trunc('day', hour) as day1,
token_address as ta1,
median(price) as token_price1
FROM avalanche.core.fact_hourly_token_prices
GROUP BY 1,2
) as a on day1 = date_trunc('day', block_timestamp)
and ta1 = TOKEN_IN
LEFT outer join (
SELECT
date_trunc('day', hour) as day2,
token_address as ta2,
median(price) as token_price2
FROM avalanche.core.fact_hourly_token_prices
Run a query to Download Data