But groupwise maximum by some expression is exactly SELECT MAX(expression) GROUP BY (criteria).<p>You could do details and groupwise maximums together with ROLLUP and some grouping-based conditional expressions in the SELECT clause, or just by UNIONing a detail query with the groupies maximums.