WITH
anchor_deposit_amount AS (
SELECT
sender,
SUM(deposit_amount_usd) AS total_deposit
FROM anchor.deposits
WHERE block_timestamp <= '2021-12-31'
GROUP BY 1),
anchor_borrrow_amount AS (
SELECT
sender,
SUM(amount_usd) AS total_borrow
FROM anchor.borrows
WHERE block_timestamp <= '2021-12-31'
GROUP BY 1)
SELECT
anchor_deposit_amount.sender AS "Sender",
anchor_deposit_amount.total_deposit AS "Total deposit (USD)",
anchor_borrrow_amount.total_borrow AS "Total borrow (USD)"
FROM anchor_deposit_amount
JOIN anchor_borrrow_amount
ON anchor_deposit_amount.sender = anchor_borrrow_amount.sender
ORDER BY 3 DESC
LIMIT 50;