boomer77Untitled Query
    Updated 2021-11-24
    with ust_supply as (
    select sum(balance) as total_ust_sup, currency, date
    from terra.daily_balances
    where currency = 'UST'
    and date > CURRENT_DATE - 30
    group by 2,3
    ),

    luna_swap_volume as (
    select sum(offer_amount_usd) as total_volume, count(distinct tx_id) as swap_count,
    'trader' as type_trade, date_trunc('day', block_timestamp) as dt
    from terra.swaps
    where swap_pair like '%LUNA%'
    and block_timestamp > CURRENT_DATE - 30
    and trader != 'terra10kjnhhsgm4jfakr85673and3aw2y4a03598e0m'
    group by 3,4
    union
    select sum(offer_amount_usd) as total_volume, count(distinct tx_id) as swap_count,
    'community pool' as type_trade, date_trunc('day', block_timestamp) as dt
    from terra.swaps
    where swap_pair like '%LUNA%'
    and block_timestamp > CURRENT_DATE - 30
    and trader = 'terra10kjnhhsgm4jfakr85673and3aw2y4a03598e0m'
    group by 3,4
    )

    select total_volume, swap_count, type_trade,
    total_ust_sup, dt
    from luna_swap_volume lu
    join ust_supply ust on
    lu.dt = ust.date
    Run a query to Download Data