Query editor
WITH c AS (SELECT * FROM dune.delphi_research.result_uni_v3_lp_positions_cls)SELECT 'quarter' AS cut, date_format(date_trunc('quarter', close_time), '%Y-%m') AS k1, 'all' AS k2,count(*) AS positions,avg(IF(vs_hodl_usd > 0, 1e0, 0e0)) AS pct_beat_hodl,count_if(days_held >= 1) AS positions_1d,avg(IF(days_held >= 1, IF(vs_hodl_usd > 0, 1e0, 0e0))) AS pct_beat_hodl_1d,avg(IF(lp_class = 'retail', IF(vs_hodl_usd > 0, 1e0, 0e0))) AS retail_pct,avg(IF(lp_class = 'retail' AND days_held >= 1, IF(vs_hodl_usd > 0, 1e0, 0e0))) AS retail_pct_1d,CAST(NULL AS double) AS cap_wtd_vs_hodl_1dFROM c GROUP BY 1, 2, 3UNION ALLSELECT 'pair x class, held >= 1d', pair_class, lp_class,count(*), avg(IF(vs_hodl_usd > 0, 1e0, 0e0)), count(*), avg(IF(vs_hodl_usd > 0, 1e0, 0e0)), NULL, NULL,IF(pair_class <> 'long-tail', sum(vs_hodl_usd) / sum(dep_usd))FROM c WHERE days_held >= 1GROUP BY 1, 2, 3ORDER BY 1, 2, 3