Heminosmoss min and max
    Updated 2022-06-28
    /*Q21. Do fees on Osmosis differ when users swap to or from different tokens? On average, which tokens have the highest and lowest swap fees on Osmosis?

    */
    with swap_from as (
    select fact_swaps.BLOCK_TIMESTAMP, fact_swaps.TX_ID , fact_transactions.GAS_USED , fact_transactions.FEE, dim_labels.LABEL
    from osmosis.core.fact_swaps
    left JOIN osmosis.core.fact_transactions on (fact_swaps.TX_ID = fact_transactions.TX_ID)
    left JOIN osmosis.core.dim_labels on (FROM_CURRENCY = ADDRESS)
    where fact_swaps.TX_STATUS = 'SUCCEEDED'
    )
    , swap_to as (
    select fact_swaps.BLOCK_TIMESTAMP, fact_swaps.TX_ID , fact_transactions.GAS_USED , fact_transactions.FEE, dim_labels.LABEL
    from osmosis.core.fact_swaps
    left JOIN osmosis.core.fact_transactions on (fact_swaps.TX_ID = fact_transactions.TX_ID)
    left JOIN osmosis.core.dim_labels on (To_CURRENCY = ADDRESS)
    where fact_swaps.TX_STATUS = 'SUCCEEDED'
    )
    , avg_from as (select 'sawp from' , avg(GAS_USED)/1e6 as GAS_USED,count(TX_ID) , LABEL from swap_from group by LABEL )
    , avg_to as (select 'sawp to' , avg(GAS_USED)/1e6 as GAS_USED,count(TX_ID) , LABEL from swap_to group by LABEL )
    select * from (select 'max sawp from ' , GAS_USED , LABEL from avg_from order by GAS_USED desc limit 1 )
    UNION
    select * from (select 'min sawp from ' , GAS_USED , LABEL from avg_from order by GAS_USED limit 1 )
    UNION
    select * from (select 'max sawp to ' , GAS_USED , LABEL from avg_to order by GAS_USED desc limit 1 )
    UNION
    select * from (select 'min sawp to ' , GAS_USED , LABEL from avg_to order by GAS_USED limit 1 )

    -- UNION
    -- select 'sawp To' , avg(GAS_USED) as GAS_USED,count(TX_ID) , LABEL from swap_to group by LABEL
    Run a query to Download Data