with deposit_table as(
SELECT
date(BLOCK_TIMESTAMP) as date,
sum(AMOUNT_USD) as deposit_amount
from
ethereum.sushi.ez_lending
WHERE
action = 'Deposit'
GROUP by date
),
withdraw_table as(
SELECT
date(BLOCK_TIMESTAMP) as date,
sum(AMOUNT_USD) as withdraw_amount
from
ethereum.sushi.ez_lending
WHERE
action = 'Withdraw'
GROUP by date
)
(SELECT
deposit_table.date ,
(deposit_amount - withdraw_amount) as Withdrawal_difference_from_deposit
FROM
deposit_table join withdraw_table on deposit_table.date = withdraw_table.date
)
UNION
( SELECT
deposit_table.date ,
deposit_amount as Withdrawal_difference_from_deposit
FROM
deposit_table left join withdraw_table on deposit_table.date = withdraw_table.date
where