angelnathUnion btw 2 table in a CTE (ETH)
    Updated 2025-03-09
    -- forked from Union btw 2 table in a CTE @ https://flipsidecrypto.xyz/studio/queries/3986a293-3f99-4df3-afa7-c157ba5867e8

    -- and ethereum.defi.ez_dex_swaps
    -- Doing same using ethereum ecosystem

    --Find the top 10 most active address
    -- using base.defi.ez_dex_swaps and base.core.dim_labels
    -- Find the top 10 most active address
    -- calcualte incoming and outgoing volumes
    -- Use CTE and join together
    WITH address_activity AS (
    -- First part (outgoing txns)
    SELECT
    --block_timestamp as date,
    origin_from_address as address,
    SUM(amount_out_usd) as outgoing_usd,
    0 as incoming_usd,
    count(*) as tx_count,


    FROM
    ethereum.defi.ez_dex_swaps

    WHERE
    block_timestamp >= dateadd(day, -7, current_timestamp())
    and amount_out_usd is not null
    Group by 1

    UNION ALL -- (combines the result of the two table)
    -- Second part (incoming txns)
    SELECT
    --block_timestamp as date,
    origin_to_address as address,
    0 as outgoing_usd,
    SUM(amount_in_usd) as incoming_usd,
    count(*) as tx_count,
    Last run: about 2 months ago
    ADDRESS
    LABEL
    TOTAL_TXN
    TOTAL_INCOMING_USD
    TOTAL_OUTGOING_USD
    1
    0x66a9893cc07d91d95644aedd05d03f95e1dba8aftoken208208565590927.410
    2
    0x51c72848c68a965f66fa7a88855f9f7784502a7f-993202513577615.40
    3
    0x68d3a973e7272eb388022a5c6518d9b2a2e66fbf-845951311766107.150
    4
    0xa69babef1ca67a37ffaf7a485dfff3382056e78c-69000881168877.750
    5
    0x0000000000001ff3684f28c67538d4d072c22734-6660985793771.540
    6
    0x1111111254eeb25477b68fb85ed929f73a960582dex6391468223989.50
    7
    0x7a250d5630b4cf539739df2c5dacb4c659f2488ddex5756658934866.460
    8
    0x1f2f10d1c40777ae1da742455c65828ff36df387-53662703781866.990
    9
    0xae2fc483527b8ef99eb5d9b44875f005ba1fae13-536210702569067.3
    10
    0x881d40237659c251811cec9c364ef91dc08d300cdex5324550992674.340
    11
    0x1ef032a3c471a99cc31578c8007f256d95e89896-50243106465352.730
    12
    0x00000000009e50a7ddb7a7b0e2ee6604fd120e49-49926129086205.780
    13
    0x93793bd1f3e35a0efd098c30e486a860a0ef7551-448230709114404.02
    14
    0x111111125421ca6dc452d289314280a0f8842a65dex40894226777508.940
    15
    0x9008d19f58aabd9ed0d60971565aa8510560ab41dex37679524690430.070
    16
    0x3328f7f4a1d1c57c35df56bbf0c9dcafca309c49-3269523781264.680
    17
    0xfc9928f6590d853752824b0b403a6ae36785e535-27414071522490.78
    18
    0xe6b1de575e7e610889ea21024834e120f92033a3-27291148104667.160
    19
    0xeff6cb8b614999d130e537751ee99724d01aa167token25424225517987.860
    20
    0xe75ed6f453c602bd696ce27af11565edc9b46b0d-24951083499276.43
    ...
    1000
    67KB
    3s