Jump to content

Group by (SQL)

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Cydebot (talk | contribs) at 21:10, 3 May 2007 (Robot - Moving category SQL statements to SQL keywords per CFD at Wikipedia:Categories for discussion/Log/2007 April 26.). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

A GROUP BY statement in SQL specifies that a SQL SELECT statement returns a list that is grouped by one or more columns, usually in order to apply some sort of aggregate function to certain columns.

Examples:

Returns a list of Department IDs along with the sum of their sales for the date of January 1, 2000.

SELECT DeptID, SUM(SaleAmount) FROM Sales
WHERE SaleDate = '01-Jan-2000'
GROUP BY DeptID