Aggregate sales by category with SQL COUNT, SUM, and AVG while handling NULL discounts and deterministic ordering.