Query editor
WITH getPrice as (SELECT price FROM prices.usdWHERE blockchain = 'arbitrum'and symbol = 'WETH'and minute = TIMESTAMP '2023-09-12 05:27:00'limit 1)SELECT ranking,address,symbol_list,good_token,txn_count,total_withdrawn_usd,total_estimated_balance_usd,whitehat_bounty_usdc,whitehat_bounty_eth,usdc_to_return,eth_to_return,total_whitehat_bounty_usd,total_unique_user,total_txn_countFROM (SELECT ROW_NUMBER() OVER (ORDER BY total_withdrawn_usd DESC) as ranking,*,COALESCE(whitehat_bounty_usdc,0) + COALESCE((whitehat_bounty_eth * price),0) as total_whitehat_bounty_usd,COUNT(*) OVER () as total_unique_user,SUM(txn_count) OVER () as total_txn_countFROM (SELECT address,ARRAY_AGG(DISTINCT symbol) as symbol_list,MAX(good_token) as good_token,COUNT(*) as txn_count,SUM(amount_usd) as total_withdrawn_usd,SUM(estimated_gev_usd) as total_estimated_balance_usd,COALESCE(SUM(CASE WHEN symbol = 'USDC' THEN whitehat_bounty END),0) as whitehat_bounty_usdc,COALESCE(SUM(CASE WHEN symbol = 'ETH' THEN whitehat_bounty END),0) as whitehat_bounty_eth,COALESCE(SUM(CASE WHEN symbol = 'USDC' THEN estimated_excess_withdrawn END),0) as usdc_to_return,COALESCE(SUM(CASE WHEN symbol = 'ETH' THEN estimated_excess_withdrawn END),0) as eth_to_returnFROM (SELECT * FROM query_3021790UNION ALLSELECT * FROM query_3021765) x LEFT JOIN query_3021906 USING (address)GROUP BY 1)p JOIN getPrice ON 1=1) gg-- LEFT JOIN query_3023649 USING (address)