select date(block_timestamp) as date_time, count(*) as total, tx_type from (
select block_timestamp, block_id, 'Deposit' as tx_type, tx_id, depositor_address, blockchain, symbol, supplied_usd
from flipside_prod_db.aave.deposits
where depositor_address like lower('{{user_address}}')
union
select block_timestamp, block_id, 'Borrow' as tx_type, tx_id, borrower_address, blockchain, symbol, borrowed_usd
from flipside_prod_db.aave.borrows
where borrower_address like lower('{{user_address}}')
union
select block_timestamp, block_id, 'Withdraw' as tx_type, tx_id, depositor_address, blockchain, symbol, withdrawn_usd
from flipside_prod_db.aave.withdraws
where depositor_address like lower('{{user_address}}')
union
select block_timestamp, block_id, 'Flashloans' as tx_type, tx_id, INITIATOR_ADDRESS, blockchain, symbol, FLASHLOAN_AMOUNT_USD
from flipside_prod_db.aave.flashloans
where INITIATOR_ADDRESS like lower('{{user_address}}'))
group by date_time, tx_type