JonasK88Wealth distribution
Updated 2021-11-15
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
›
⌄
/*18. [Easy] Wealth distribution*/
WITH toAddress AS (
SELECT
to_address AS address,
SUM(rune_amount_usd) AS to_amount_usd
FROM thorchain.transfers
GROUP BY 1
ORDER BY 1 DESC
),
fromAddress AS (
SELECT
from_address AS address,
SUM(rune_amount_usd) AS from_amount_usd
FROM thorchain.transfers
GROUP BY 1
ORDER BY 1 DESC
),
totalAmount AS (
SELECT
coalesce(fromAddress.address, toAddress.address) AS address,
round(to_amount_usd - from_amount_usd,2) AS amount_usd
FROM fromAddress
JOIN toAddress
ON fromAddress.address = toAddress.address
ORDER BY 2 DESC
)
SELECT
CASE
WHEN amount_usd < 10 THEN 'a. Less than 10 USD'
WHEN amount_usd >= 10 AND amount_usd < 100 THEN 'b. between 10 and 100 USD'
WHEN amount_usd >= 100 AND amount_usd < 500 THEN 'c. between 100 and 500 USD'
WHEN amount_usd >= 500 AND amount_usd < 1000 THEN 'd. between 500 and 1,000 USD'
WHEN amount_usd >= 1000 AND amount_usd < 5000 THEN 'e. between 1,000 and 5,000 USD'
WHEN amount_usd >= 5000 AND amount_usd < 10000 THEN 'f. between 5,000 and 10,000 USD'