Tobi_1eager-azure
Updated 2024-09-28
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 holder_balances AS (
-- Step 1: Calculate the total token balance for each holder (adjusted by decimals)
SELECT
TO_ADDRESS AS holder_address,
SUM(RAW_AMOUNT / POWER(10, DECIMALS)) AS balance -- Adjusting by decimals
FROM
base.core.ez_token_transfers
WHERE
CONTRACT_ADDRESS = '0x532f27101965dd16442e59d40670faf5ebb142e4'
GROUP BY
TO_ADDRESS, DECIMALS
UNION ALL
SELECT
FROM_ADDRESS AS holder_address,
-SUM(RAW_AMOUNT / POWER(10, DECIMALS)) AS balance -- Adjusting for outgoing transactions
FROM
base.core.ez_token_transfers
WHERE
CONTRACT_ADDRESS = '0x532f27101965dd16442e59d40670faf5ebb142e4'
GROUP BY
FROM_ADDRESS, DECIMALS
),
aggregated_balances AS (
-- Step 2: Sum up all balances to find the final balance for each holder
SELECT
holder_address,
SUM(balance) AS final_balance
FROM
holder_balances
GROUP BY
holder_address
),
QueryRunArchived: QueryRun has been archived