Field note · August 2, 2025
discount_pct by category: a 16% spread
Real group means for one column across 6 segments, and what the pooled average conceals.
Breaking discount_pct down by category on retail-orders, because the headline average is 0.10 and no segment is actually there.
home— mean 0.10, median 0.06 (1,279 rows)electronics— mean 0.10, median 0.00 (960 rows)grocery— mean 0.10, median 0.00 (1,188 rows)apparel— mean 0.09, median 0.00 (1,696 rows)sports— mean 0.09, median 0.00 (789 rows)beauty— mean 0.09, median 0.00 (1,088 rows)
Top to bottom that is 0.10 against 0.09, a spread of 16.1%. The pooled average is 0.10.
select category,
count(*) as rows,
round(avg(discount_pct)::numeric, 2) as mean,
percentile_cont(0.5) within group (order by discount_pct) as median
from retail_orders
group by 1
order by mean desc;The groups are close enough that the pooled average is a fair summary. That is worth confirming rather than assuming: the check costs one query and the failure mode is invisible.
Notice the mean and median columns disagree most in home, where the mean sits well above the median. Always compute both in the group-by. The comparison between them per segment is free and tells you whether you are looking at a level difference or a tail difference.
This is the setup for Simpson's paradox — the case where every segment moves one way and the total moves the other.