Query editor
with r as (select *, date(block_time + interval '8' hour) d8, at_timezone(block_time, 'America/New_York') et from dune.okxweb3wallet.result_xl_uni_xs_trades_1109_1122),r2 as (select *, case when day_of_week(et) in (6,7) then 'weekend' when (hour(et)*60+minute(et)) between 570 and 959 then 'regular' else 'offhours' end sess from r),fq as (select tx_from, count(distinct tx_hash) ntx from r2 group by 1)select 'tot' part, '-' k1, '-' k2, sum(usd) usd, cast(count(*) as double) n, cast(count(distinct tx_from) as double) n2, cast(count(distinct pool) as double) n3, cast(count(distinct tx_hash) as double) n4 from r2union all select 'unpriced', '-', '-', sum(xamt), cast(count_if(usd is null) as double), 0, 0, 0 from r2 where usd is nullunion all select 'tok', sym, '-', sum(usd), count(*), count(distinct tx_from), count(distinct pool), approx_percentile(usd,0.5) from r2 group by 2union all select 'ver', version, '-', sum(usd), count(*), count(distinct tx_from), count(distinct pool), 0 from r2 group by 2union all select 'ptype', ptype, '-', sum(usd), count(*), count(distinct tx_from), count(distinct pool), 0 from r2 group by 2union all select 'day', cast(d8 as varchar), '-', sum(usd), count(*), count(distinct tx_from), 0, 0 from r2 group by 2union all select 'daytok', cast(d8 as varchar), sym, sum(usd), count(*), 0, 0, 0 from r2 where sym in ('NVDAx','QQQx','SPYx','BRK.Bx','SPCXx','TSLAx') group by 2,3union all select 'sess', sess, '-', sum(usd), count(*), count(distinct date_trunc('hour', et)), 0, 0 from r2 group by 2union all select 'pool', lower(to_hex(pool)), max(sym)||'/'||max(osym)||' v'||max(version), sum(usd), count(*), count(distinct tx_from), approx_percentile(usd,0.5), 0 from r2 group by 2union all select 'size', case when usd<10 then '1 <10' when usd<100 then '2 10-100' when usd<1000 then '3 100-1k' when usd<10000 then '4 1k-10k' else '5 >=10k' end, '-', sum(usd), count(*), 0, 0, 0 from r2 group by 2union all select 'side', side, sym, sum(usd), count(*), 0, 0, 0 from r2 where not xx group by 2,3union all select 'txto', lower(to_hex(tx_to)), '-', sum(usd), count(*), count(distinct tx_from), count(distinct tx_hash), 0 from r2 group by 2union all select 'freq', case when f.ntx>=280 then 'HF' else 'low' end, '-', sum(usd), count(*), count(distinct r2.tx_from), 0, 0 from r2 join fq f on f.tx_from=r2.tx_from group by 2union all select 'topfrom', lower(to_hex(r2.tx_from)), '-', sum(usd), count(*), max(f.ntx), count(distinct lower(to_hex(tx_to))), 0 from r2 join fq f on f.tx_from=r2.tx_from group by 2