Afonso_DiazGrouping transactions
    Updated 2024-10-05
    with t as (
    select
    tx_hash,
    block_timestamp,
    trader,
    a.symbol_out,
    b.symbol_in
    from near.defi.ez_dex_swaps a
    join near.defi.ez_dex_swaps b
    using (tx_hash)
    where platform = 'v2.ref-finance.near'

    and a.swap_index = (select min(swap_index) from near.defi.ez_dex_swaps c
    where a.tx_hash = c.tx_hash)

    and b.swap_index = (select max(swap_index) from near.defi.ez_dex_swaps c
    where b.tx_hash = c.tx_hash)
    qualify row_number() over (partition by tx_hash order by block_timestamp) = 1
    ),

    t2 as (
    select
    tx_hash,
    block_timestamp,
    trader,
    (select sum(amount_out_usd) from near.defi.ez_dex_swaps b where t.tx_hash = b.tx_hash and t.symbol_out = b.symbol_out) as amount_in_usd, --Issue with flipside tables
    (select sum(amount_in_usd) from near.defi.ez_dex_swaps b where t.tx_hash = b.tx_hash and t.symbol_in = b.symbol_in) as amount_out_usd, -- Issue with flipside tables
    (select sum(amount_out) from near.defi.ez_dex_swaps b where t.tx_hash = b.tx_hash and t.symbol_out = b.symbol_out) as amount_in, --Issue with flipside tables
    (select sum(amount_in) from near.defi.ez_dex_swaps b where t.tx_hash = b.tx_hash and t.symbol_in = b.symbol_in) as amount_out, -- Issue with flipside tables
    symbol_out as symbol_in,
    symbol_in as symbol_out
    from t
    ),

    t3 as (
    select *,
    QueryRunArchived: QueryRun has been archived