Query editor
with ev as (select *,case when debt_usd is not null and coll_usd is not null and debt_usd < 1e9 and coll_usd < 2*debt_usd + 1000 then greatest(coll_usd - debt_usd, 0) end bonusfrom dune.fadz2323.result_eth_liq_oct_dec_2026),t as (select h, min(proto) pgrp, min(t) t, min(txi) txi, min(liquidator) liq, count(*) n_ev, count(bonus) n_priced, sum(bonus) bonus, max(eth_usd) eth_usd,coalesce(max(gas_used * priority_fee_per_gas), 0) / 1e18 prio_eth, coalesce(max(gas_used * base_fee_per_gas), 0) / 1e18 base_eth, coalesce(max(cb_eth), 0) cb_eth, max(svr_idx) svr_idxfrom ev group by h),tx as (select *, (prio_eth + cb_eth) * eth_usd builder, bonus - (prio_eth + cb_eth + base_eth) * eth_usd net, base_eth * eth_usd base_usd,case when svr_idx is not null and txi - svr_idx = 1 then 1 else 0 end is_svr,case when t < timestamp '2026-11-01' then '2026-10' when t < timestamp '2026-12-01' then '2026-11' else '2026-12-01..03' end mofrom t where n_ev = n_priced and eth_usd is not null),m as (select mo, pgrp, count(*) n_tx, sum(bonus) bonus, sum(builder) builder, sum(base_usd) base, sum(net) net, count(distinct liq) winners, sum(bonus) filter (where is_svr = 1) svr_bonus,avg(base_usd) avg_base_per_tx, approx_percentile(base_usd, 0.5) med_base_per_txfrom tx group by grouping sets ((mo, pgrp), (mo))),rk as (select mo, liq, sum(net) n, row_number() over (partition by mo order by sum(net) desc) r from tx group by mo, liq),rr as (select mo, max(n) filter (where r = 1) r1, max(n) filter (where r = 5) r5, max(n) filter (where r = 10) r10, max(n) filter (where r = 20) r20, max(n) filter (where r = 30) r30, count_if(n > 5000) n_gt5k from rk group by mo)select m.*, rr.r1, rr.r5, rr.r10, rr.r20, rr.r30, rr.n_gt5k from m left join rr on rr.mo = m.mo and m.pgrp is nullorder by mo, pgrp