Thursday, December 20

Differences between GROUP BY and COMPUTE




The following summarizes the differences between COMPUTE and GROUP BY:



  • GROUP BY produces a single result set. There is one row for each group containing only the grouping columns and aggregate functions that show the sub-aggregate for that group. The select list can contain only the grouping columns and aggregate functions.

  • COMPUTE produces multiple result sets. One kind of result set contains the detail rows for each group containing the expressions from the select list. The other type of result set contains the sub-aggregate for a group, or the total aggregate for the SELECT statement. The select list can contain expressions other than the grouping columns or aggregate functions. The aggregate functions are specified in the COMPUTE clause, not in the select list.