Query editor
with dex_prices as (select*from prices.usdwhere blockchain = 'base'and contract_address = 0x4498cd8Ba045E00673402353f5a4347562707e7Dorder by minute desclimit 1),dex_prices_backup as (selectblock_time, (casewhen token_bought_address = 0x4498cd8Ba045E00673402353f5a4347562707e7D then amount_usd/token_bought_amountwhen token_sold_address = 0x4498cd8Ba045E00673402353f5a4347562707e7D then amount_usd/token_sold_amountelse 0 end) as token_price, (casewhen token_bought_address = 0x4498cd8Ba045E00673402353f5a4347562707e7D then token_bought_symbolwhen token_sold_address = 0x4498cd8Ba045E00673402353f5a4347562707e7D then token_sold_symbolelse 'N/A' end) as token_symbol, amount_usd, token_bought_amount, token_sold_amountfrom dex.tradeswhere (token_bought_address = 0x4498cd8Ba045E00673402353f5a4347562707e7Dor token_sold_address = 0x4498cd8Ba045E00673402353f5a4347562707e7D)and amount_usd > 0order by block_time desclimit 1)selectp.symbol, coalesce(d.price, b.token_price) as price, coalesce(d.contract_address, p.contract_address) as contract_addressfrom tokens.erc20 pleft join dex_prices d on d.contract_address = p.contract_addressleft join dex_prices_backup b on p.symbol = b.token_symbolwhere p.blockchain = 'base'and p.contract_address = 0x4498cd8Ba045E00673402353f5a4347562707e7D