--- title: "GROUP BY (Transact-SQL) | Microsoft Docs" ms.custom: "" ms.date: "03/01/2019" ms.prod: sql ms.prod_service: "database-engine, sql-database, sql-data-warehouse, pdw" ms.reviewer: "" ms.technology: t-sql ms.topic: "language-reference" f1_keywords: - "GROUP" - "CUBE" - "ROLLUP" - "GROUPING_SETS_TSQL" - "GROUP BY" - "GROUPING SETS" - "GROUP_BY_TSQL" - "GROUP_TSQL" - "CUBE_TSQL" - "ROLLUP_TSQL" dev_langs: - "TSQL" helpviewer_keywords: - "GROUP BY clause, about GROUP BY clause" - "dividing tables into groups" - "GROUPING SETS" - "GROUP BY clause" - "table groups [SQL Server]" - "groups [SQL Server], tables divided into groups" - "summary values [SQL Server]" ms.assetid: 40075914-6385-4692-b4a5-62fe44ae6cb6 author: shkale-msft ms.author: shkale monikerRange: ">=aps-pdw-2016||=azuresqldb-current||=azure-sqldw-latest||>=sql-server-2016||=sqlallproducts-allversions||>=sql-server-linux-2017||=azuresqldb-mi-current" --- # SELECT - GROUP BY- Transact-SQL [!INCLUDE[tsql-appliesto-ss2008-all-md](../../includes/tsql-appliesto-ss2008-all-md.md)] A SELECT statement clause that divides the query result into groups of rows, usually for the purpose of performing one or more aggregations on each group. The SELECT statement returns one row per group. ## Syntax ![Topic link icon](../../database-engine/configure-windows/media/topic-link.gif "Topic link icon") [Transact-SQL Syntax Conventions (Transact-SQL)](../../t-sql/language-elements/transact-sql-syntax-conventions-transact-sql.md) ``` -- Syntax for SQL Server and Azure SQL Database -- ISO-Compliant Syntax GROUP BY { column-expression | ROLLUP ( [ ,...n ] ) | CUBE ( [ ,...n ] ) | GROUPING SETS ( [ ,...n ] ) | () --calculates the grand total } [ ,...n ] ::= column-expression | ( column-expression [ ,...n ] ) ::= () --calculates the grand total | | ( [ ,...n ] ) ::= | ROLLUP ( [ ,...n ] ) | CUBE ( [ ,...n ] ) -- For backward compatibility only. -- Non-ISO-Compliant Syntax for SQL Server and Azure SQL Database GROUP BY [ ALL ] column-expression [ ,...n ] | column-expression [ ,...n ] [ WITH { CUBE | ROLLUP } ] ``` ``` -- Syntax for Azure SQL Data Warehouse GROUP BY { column-name [ WITH (DISTRIBUTED_AGG) ] | column-expression | ROLLUP ( [ ,...n ] ) } [ ,...n ] ``` ``` -- Syntax for Parallel Data Warehouse GROUP BY { column-name [ WITH (DISTRIBUTED_AGG) ] | column-expression } [ ,...n ] ``` ## Arguments ### *column-expression* Specifies a column or a non-aggregate calculation on a column. This column can belong to a table, derived table, or view. The column must appear in the FROM clause of the SELECT statement, but is not required to appear in the SELECT list. For valid expressions, see [expression](~/t-sql/language-elements/expressions-transact-sql.md). The column must appear in the FROM clause of the SELECT statement, but is not required to appear in the SELECT list. However, each table or view column in any nonaggregate expression in the \