binhachon30. [Hard] Sankey Swap Diagrams - Labels
Updated 2021-12-18
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
›
⌄
with pool_list as (
select asset, row_number() over (order by asset) as ID from (
select distinct from_asset as asset from thorchain.swaps
where (to_asset = 'THOR.RUNE' or from_asset = 'THOR.RUNE')
union
select distinct to_asset as asset from thorchain.swaps
where (to_asset = 'THOR.RUNE' or from_asset = 'THOR.RUNE')
)
),
query_data as(
select
case when position('-', from_asset, 1) = 0 then from_asset else
substr(from_asset, 1, position('-', from_asset, 1) - 1) end as source,
source_id.ID - 1 as source_id,
case when position('-', to_asset, 1) = 0 then to_asset else
substr(to_asset, 1, position('-', to_asset, 1) - 1) end as destination,
case when destination = 'THOR.RUNE' then destination_id.ID - 1 else destination_id.ID + 30 end as destination_id, sum(from_amount_usd) as volume, count(tx_id) as frequency from thorchain.swaps
left join pool_list source_id on source_id.asset = from_asset
left join pool_list destination_id on destination_id.asset = to_asset
where (to_asset = 'THOR.RUNE' or from_asset = 'THOR.RUNE')
group by source, source_id, destination, destination_id
order by source_id, destination_id
)
select * from (
select distinct source as label, source_id as ID from query_data
union
select distinct destination as label, destination_id as ID from query_data
)
order by ID
Run a query to Download Data