Group by (SQL)

A   statement in SQL specifies that a SQL  statement partitions result rows into groups, based on their values in one or several columns. Typically, grouping is used to apply some sort of aggregate function for each group.

The result of a query using a  statement contains one row for each group. This implies constraints on the columns that can appear in the associated  clause. As a general rule, the  clause may only contain columns with a unique value per group. This includes columns that appear in the  clause as well as aggregates resulting in one value per group.

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

In the following example one can ask "How many units were sold in each region for every ship date?":

The following code returns the data of the above pivot table which answers the question "How many units were sold in each region for every ship date?":

Common groupings
Common grouping (aggregation) functions include:
 * Count(expression) - Quantity of matching records (per group)
 * Sum(expression) - Summation of given value (per group)
 * Min(expression) - Minimum of given value (per group)
 * Max(expression) - Maximum of given value (per group)
 * Avg(expression) - Average of given value (per group)