Export (0) Print
Expand All

GROUP BY Clause

SQL Server 2000

Specifies the groups (equivalence classes) into which output rows are to be placed and, if aggregate functions are included in the SELECT clause <select list>, calculates a summary value for each group. When GROUP BY is specified, either each column in any nonaggregate expression in the select list should be included in the GROUP BY list or the GROUP BY expression must match exactly the select list expression.

Note  If the ORDER BY clause is not specified, groups returned using the GROUP BY clause are not in any particular order. It is recommended that you always use the ORDER BY clause to specify a particular ordering of the data.

Syntax
[ GROUP BY group_by_expression [ ,...n ] ] 
Arguments
group_by_expression
Is an expression on which grouping is performed. group_by_expression is also known as a grouping column. group_by_expression can be a column or a nonaggregate expression that references a column. A column alias that is defined in the select list cannot be used to specify a grouping column. Aggregate expressions cannot be specified in a group_by_expression.

Note  Columns of type ntext and image cannot be used in group_by_expression.

Note  GROUP BY ALL is not supported in SQL Server CE.

Show:
© 2014 Microsoft