Query editor
with dex_prices as (select*from prices.usdwhere blockchain = 'bnb'and contract_address = 0x5921DEE8556c4593EeFCFad3CA5e2f618606483border by minute desclimit 1),dex_prices_backup as (selectblock_time, (casewhen token_bought_address = 0x5921DEE8556c4593EeFCFad3CA5e2f618606483b then amount_usd/token_bought_amountwhen token_sold_address = 0x5921DEE8556c4593EeFCFad3CA5e2f618606483b then amount_usd/token_sold_amountelse 0 end) as token_price, (casewhen token_bought_address = 0x5921DEE8556c4593EeFCFad3CA5e2f618606483b then token_bought_symbolwhen token_sold_address = 0x5921DEE8556c4593EeFCFad3CA5e2f618606483b then token_sold_symbolelse 'N/A' end) as token_symbol, amount_usd, token_bought_amount, token_sold_amountfrom dex.tradeswhere (token_bought_address = 0x5921DEE8556c4593EeFCFad3CA5e2f618606483bor token_sold_address = 0x5921DEE8556c4593EeFCFad3CA5e2f618606483b)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 = 'bnb'and p.contract_address = 0x5921DEE8556c4593EeFCFad3CA5e2f618606483b