feyikemirival-salmon
    Updated 2024-11-06
    WITH Stats AS(
    SELECT
    Tx_hash,
    Swapper,
    nvl(amount_in_usd, amount_out_usd) AS VOLUME
    FROM aptos.defi.ez_dex_swaps
    WHERE BLOCK_TIMESTAMP :: DATE >= '2024-01-01'
    and amount_out_usd < 1e6 and amount_in_usd < 1e6
    )

    SELECT
    COUNT(DISTINCT Tx_hash) AS Trades,
    COUNT(DISTINCT Swapper) AS Traders,
    SUM(Volume) AS Total_Volume,
    FROM Stats

    -- With stats AS(
    -- SELECT
    -- COUNT(DISTINCT Tx_hash) AS Trades,
    -- COUNT(DISTINCT Swapper) AS Traders,
    -- sum(case when amount_out_usd is not null then amount_out_usd else amount_in_usd end) AS Volume
    -- nvl(amount_in_usd, amount_out_usd) AS VOLUME
    -- SUM((AMOUNT_IN_USD + AMOUNT_OUT_USD)/2) AS Volume
    -- FROM
    -- aptos.defi.ez_dex_swaps
    -- WHERE BLOCK_TIMESTAMP :: DATE >= '2024-01-01'
    -- and amount_out_usd < 1e6 and amount_in_usd < 1e6
    -- )

    -- SELECT
    -- Trades AS Total_trades,
    -- Traders AS Total_Traders,
    -- Volume AS Total_Traded_Volume,
    -- Total_Trades / Total_Traders AS Avg_Trades_Per_Users,
    -- Total_Traded_Volume / Total_Traders AS AVG_Traded_vol_per_Users
    -- FROM Stats
    QueryRunArchived: QueryRun has been archived