Query editor
-- DUNE ANALYTICS QUERY DIGESTIBLE -------------------------------------------------------------------------------------------------------------- WITH = To denote a CTE-- Frequency AS (), = To count the number of USDC/WETH Swaps per week-- Volume AS (Base X 2nd Query) =---- WITH Base AS (), =---- [2nd Query], =-- dex_trades AS () =-- SELECT COLUMNS-- FROM Volume AS V-- LEFT JOIN frequency AS F ON f.time = v.time-- LEFT JOIN dex_trades AS dx ON dx.week = v.time------------------------------------------------------------------------------------------------------------------------------------------------------WITHfrequency AS(SELECT date_trunc('quarter', evt_block_time) AS time, count(*) as num_swapsFROM uniswap_v2_ethereum.Pair_evt_SwapWHERE contract_address = 0xb4e16d0168e52d35cacd2c6185b44281ec28c9dcGROUP BY 1),volume AS(WITH base AS(SELECT date_trunc('quarter', s.evt_block_time) AS time, CASE WHEN cast(amount0Out AS DOUBLE) = 0 THEN p.token1 ELSE p.token0 END AS token_bought_address, CASE WHEN cast(amount0Out AS DOUBLE) = 0 THEN cast(amount1Out AS DOUBLE) ELSE cast(amount0Out AS DOUBLE) END AS token_bought_amount_rawFROM uniswap_v2_ethereum.Pair_evt_Swap AS sLEFT JOIN uniswap_v2_ethereum.Factory_evt_PairCreated AS p ON p.pair = s.contract_addressWHERE s.contract_address = 0xb4e16d0168e52d35cacd2c6185b44281ec28c9dc)SELECT date_trunc('quarter', b.time) AS time, SUM (token_bought_amount_raw / pow(10,COALESCE(t.decimals,18)) * p.price) AS total_usd_amountFROM base AS bLEFT JOIN tokens.erc20 AS t ON t.contract_address = b.token_bought_addressLEFT JOIN prices.usd AS p ON p.minute = b.timeAND p.blockchain = 'ethereum'AND p.contract_address = b.token_bought_addressGROUP BY 1),dex_trades AS(SELECT date_trunc('month',block_date) AS quarter, count(*) AS num_swaps_dx, sum(amount_usd) AS total_usd_amount_dxFROM dex.tradesWHERE blockchain = 'ethereum'AND project_contract_address = 0xb4e16d0168e52d35cacd2c6185b44281ec28c9dcGROUP BY 1)SELECT f.num_swaps, v.time, v.total_usd_amount, dx.total_usd_amount_dx, dx.num_swaps_dxFROM volume AS vLEFT JOIN frequency AS f ON f.time = v.timeLEFT JOIN dex_trades AS dx ON dx.quarter = v.time