Query editor
WITHfirst_deposits as (SELECT onBehalfOf as address, min(DATE_TRUNC('day',evt_block_time)) as block_time --reserve as underlyingFROM aave_v3_arbitrum.L2Pool_evt_SupplyGROUP BY 1), calendar as (SELECT explode (sequence(to_date('2022-03-15'), now(), interval 1 day)) as date_day), first_borrows as (SELECT onBehalfOf as address, min(DATE_TRUNC('day',evt_block_time)) as block_time --reserve as underlyingFROM aave_v3_arbitrum.L2Pool_evt_BorrowGROUP BY 1), first_deposits_eth as (SELECT onBehalfOf as address, min(DATE_TRUNC('day',evt_block_time)) as block_time --reserve as underlyingFROM aave_v2_ethereum.LendingPool_evt_BorrowGROUP BY 1), first_borrows_eth as (SELECT onBehalfOf as address, min(DATE_TRUNC('day',evt_block_time)) as block_time --reserve as underlyingFROM aave_v2_ethereum.LendingPool_evt_BorrowGROUP BY 1)SELECTd.date_day, b.no_users as no_borrowers, d.no_users as no_depositors, sum(b.no_users) over (order by d.date_day asc) as total_borrowers, sum(b.no_eth_users) over (order by d.date_day asc) as total_eth_borrowers, sum(d.no_users) over (order by d.date_day asc) as total_depositors, sum(d.no_eth_users) over (order by d.date_day asc) as total_eth_depositors, sum(b.no_users) over (order by d.date_day asc) / sum(d.no_users) over (order by d.date_day asc) as borrows_vs_deposits, sum(d.no_eth_users) over (order by d.date_day asc) / sum(d.no_users) over (order by d.date_day asc) as depositors_on_eth_percent, sum(b.no_eth_users) over (order by d.date_day asc) / sum(b.no_users) over (order by d.date_day asc) as borrowers_on_eth_percentFROM (SELECTc.date_day, count(distinct fd.address) as no_users, count(distinct fde.address) as no_eth_usersFROMcalendar cLEFT JOIN first_deposits fd on fd.block_time = c.date_dayLEFT JOIN first_deposits_eth fde on fde.address = fd.addressGROUP BY 1) dJOIN (SELECTc.date_day, count(distinct fd.address) as no_users, count(distinct fbe.address) as no_eth_usersFROMcalendar cLEFT JOIN first_borrows fd on fd.block_time = c.date_dayLEFT JOIN first_borrows_eth fbe on fbe.address = fd.addressGROUP BY 1) b on b.date_day = d.date_day