SELECT
symbols.symbol,
COALESCE(SUM(CAST(@portals.transactions.deposits.amountusd AS DOUBLE)),0) AS total_deposit_volume,
COALESCE(SUM(CAST(@portals.transactions.swaps.inputamount AS DOUBLE)),0) AS total_swap_volume,
COALESCE(SUM(CAST(@portals.transactions.withdraws.amountusd AS DOUBLE)),0) AS total_withdrawal_volume
FROM (SELECT symbol FROM @portals.transactions.deposits
UNION
SELECT inputtoken FROM @portals.transactions.swaps
UNION
SELECT symbol FROM @portals.transactions.withdraws
) symbols
LEFT JOIN @portals.transactions.deposits ON symbols.symbol=@portals.transactions.deposits.symbol
LEFT JOIN @portals.transactions.swaps ON symbols.symbol=@portals.transactions.swaps.inputtoken
LEFT JOIN @portals.transactions.withdraws ON symbols.symbol=@portals.transactions.withdraws.symbol
GROUP BY symbols.symbol
ORDER BY total_deposit_volume DESC
LIMIT 10