Query editor
With transact_currency as (select distinct currency_symbol, currency_contractfrom nft.trades where nft_contract_address=0x76BE3b62873462d2142405439777e971754E8E77and currency_symbol is not null),price_info as(select date_trunc('day',hour) as block_date,contract_address,approx_percentile(median_price,0.5) as median_pricefrom dex.prices where contract_address in (select currency_contract from transact_currency where currency_symbol != 'PRIME') -- dex prices has missing prime datagroup by 1,2union all--union prime price(SELECTblock_date,contract_address,approx_percentile(price,0.5) as median_priceFROM (SELECTblock_date,0xb23d80f5fefcddaa212212f028021b41ded428cf "contract_address",(CASE WHEN token_bought_address = 0xb23d80f5fefcddaa212212f028021b41ded428cf THEN amount_usd/token_bought_amount ELSE amount_usd/token_sold_amount END) as priceFROM (SELECT * FROM dex.trades WHERE token_bought_address = 0xb23d80f5fefcddaa212212f028021b41ded428cfUNION ALLSELECT * FROM dex.trades WHERE token_sold_address = 0xb23d80f5fefcddaa212212f028021b41ded428cf))GROUP BY 1,2ORDER BY 1)),time_series AS (SELECT block_dateFROM UNNEST(SEQUENCE(TIMESTAMP '2021-03-27', CURRENT_DATE, interval '1' day)) AS tbl(block_date)),adj_price_info as(SELECTts.block_date,pi.contract_address,pi.median_price as usd_median_price,pi.median_price / (SELECT median_price FROM price_infoWHERE contract_address = 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2 AND block_date = pi.block_date) AS eth_median_priceFROM time_series tsLEFT JOIN price_info pi ON ts.block_date = pi.block_dateORDER BY ts.block_date, pi.contract_address),os_sales as (selectdate_trunc('day',block_time) as trade_date, -- some data in block_date is emptycase when currency_symbol='ETH' then 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2 else currency_contract end as trade_currency_contract, -- some ETH has 0x0000000 as currency contract*from nft.tradeswhere nft_contract_address=0x76BE3b62873462d2142405439777e971754E8E77)