with borrow as (select sum(amount_usd) as total_borrowed,lending_pool
from flipside_prod_db.crosschain.ez_borrowing
where platform like 'sushi'
and ACTION like 'Borrow'
and amount_usd is not null
group by lending_pool),
repaying as (select sum(amount_usd) as total_repaid,lending_pool
from flipside_prod_db.crosschain.ez_borrowing
where platform like 'sushi'
and ACTION like 'Repay'
and amount_usd is not null
group by lending_pool)
select count(b.lending_pool) as pools
from borrow b
join repaying r on r.lending_pool = b.lending_pool
where total_repaid > total_borrowed