Postgresql – Add an aggregate over full table outside the buckets to every bucket row
I have a query that filters the emails of people who "have a quantity" bigger than the median over all quantities found in the table: SELECT AVG(quantity) AS avg_quantity, email FROM table GROUP BY email HAVING AVG(quantity) > (SELECT PERCENTILE_DISC(0.5)…