Query editor
with new as(select s.evt_block_time,s.tokenIn,s.tokenOut,s.amountIn,s.amountOut,d.token_pair,d.amount_usd,d.tx_hashfrom integral_size_ethereum.TwapRelayer_New_evt_Sell sinner join dex.trades don d.tx_hash=s.evt_tx_hashand d.tx_to=0x881d40237659c251811cec9c364ef91dc08d300cand d.blockchain='ethereum'and d.block_date>=cast('2023-07-01' as timestamp)and d.block_date<=cast('2023-10-31' as timestamp)),--and s.evt_block_time > NOW() - INTERVAL '30' day),old as(select s.evt_block_time,s.tokenIn,s.tokenOut,s.amountIn,s.amountOut,d.token_pair,d.amount_usd,d.tx_hashfrom integral_size_ethereum.TwapRelayer_evt_Swap sinner join dex.trades don d.tx_hash=s.evt_tx_hashand d.tx_to=0x881d40237659c251811cec9c364ef91dc08d300cand d.blockchain='ethereum'and d.block_date>=cast('2023-07-01' as timestamp)and d.block_date<=cast('2023-10-31' as timestamp)--and s.evt_block_time > NOW() - INTERVAL '30' day),res as(select * from newunion allselect * from old),final_res as(select evt_block_time,p1.symbol as token_in,p2.symbol as token_out,coalesce(amountIn/power(10,p1.decimals)*p1.price,amountOut/power(10,p2.decimals)*p2.price) as Integral_volume,amount_usd as metamask_volume,token_pair,tx_hashfrom res rleft join prices.usd p1on p1.contract_address=r.tokenInand p1.blockchain='ethereum'and p1.minute=date_trunc('minute', r.evt_block_time)left join prices.usd p2on p2.contract_address=r.tokenOutand p2.blockchain='ethereum'and p2.minute=date_trunc('minute', r.evt_block_time)),