Group By Operator

The Group By operator lets you divide input rows into groups and apply aggregate functions to produce an output row for each group. The Group By operator is similar to the Aggregate operator.

Group By divides the input rows into groups based on criteria you specify and then applies the aggregation functions to the rows in each group. To define the groups, you pick one or more columns from the input source. A group consists of all rows of the input where the values for the specified aggregate columns are identical. For example, suppose your input data describes employees and contains a column named DEPT_NO. You can group by that column to obtain aggregate information for the employees in each department. If you specify more than one group-by column, the values for those columns must be the same throughout all rows of the group.

You also have the option when defining the group-by rows of including the group-by column in the output result set. In the example above, therefore, we could choose to include the DEPT_NO column in our result set. Otherwise, only the columns calculated based on the aggregate functions are included.

These aggregate functions are available for use with the Group By operator: Sum, Average, Maximum, Minimum, Count, First, Last, Population Variance, Sample Variance, Population Standard Deviation, and Sample Standard Deviation.

Send your feedback on this help topic to Sybase Technical Publications: pubs@sybase.com

Your comments will be sent to the technical publications staff at Sybase, Inc. For product-related issues or technical support, contact Sybase Technical Support at 1-800-8SYBASE.