SQL GROUP BY Clause
SQL GROUP BY Clause
The GROUP BY clause is used to summarize data based on grouping criteria. For each group one column is returned in result set.
Syntax
SELECT expression1, expression2, … expressionN, aggregate function (aggregate expression)
FROM Table Name
WHERE conditions
GROUP BY expression1, expression2, expressionN;
In this example we will display the total for each SalesOrderID column from table SalesOrderDetail of database AdventureWorks2014,
the query is given below.
SELECT SalesOrderID, SUM(LineTotal) AS Total, ModifiedDate
FROM Sales.SalesOrderDetail
GROUP BY SalesOrderID, ModifiedDate
ORDER BY SalesOrderID;
Advertising