Query editor
withtrove_updates as (select(evt_block_number, evt_index) as seq,_borrower,_coll,_debtfromliquity_ethereum.BorrowerOperations_evt_TroveUpdatedunion allselect(evt_block_number, evt_index),_borrower,_coll,_debtfromliquity_ethereum.TroveManager_evt_TroveUpdated),troves as (selectcast(max_by(_coll, seq) as double) / 1e18 as coll,cast(max_by(_debt, seq) as double) / 1e18 as debtfromtrove_updatesgroup by_borrower),cume as (selectcoll / debt as nominal_collateral_ratio,sum(debt) over (order bycoll / debt) as debt_in_frontfromtroveswheredebt > 0)selectnominal_collateral_ratio,debt_in_frontfromcume,(selectsum(debt) as total_debtfromtroves)wheredebt_in_front < 0.99 * total_debt -- zoom in on the useful range, as there are a few Troves with absurdly high CRsorder bynominal_collateral_ratio