Computations like 'average salary per department', 'cheapest product per category' or cumulative sums are dramatically faster as a single query using Postgres window functions (OVER / PARTITION BY / ROW_NUMBER / ROWS BETWEEN) than by issuing two queries and combining in Ruby. They compose inside Rails, encapsulate cleanly in a DTO, and pair well with Ruby pattern matching on the result.