Export (0) Print
Expand All
Expand Minimize

GROUP BY Clause (SQL Server Compact)

Specifies the groups (equivalence classes) that output rows are to be placed in. If aggregate functions are included in the SELECT clause <select list>, the GROUP BY clause calculates a summary value for each group.


[ GROUP BY group_by_expression [ ,...n ] ] 

group_by_expression

An expression that grouping is performed on. The group_by_expression argument is also known as a grouping column. For more information, see Remarks.

The group_by_expression parameter 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.

ms173245.note(en-us,SQL.100).gifNote:
Columns of type ntext and image cannot be used in group_by_expression.

When GROUP BY is specified, the GROUP BY expression must exactly match the select list expression, or each column in any nonaggregate expression in the select list must be included in the GROUP BY list.

ms173245.note(en-us,SQL.100).gifNote:
GROUP BY ALL is not supported in SQL Server Compact 3.5.

The following example returns a list of all orders grouped by product ID.

SELECT [Product ID], COUNT(*) AS Expr1 FROM [Order Details] GROUP BY [Product ID]
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft