Grouped Set Functions - the GROUP BY Clause
Normally, set functions return a single value, calculated from the set of all values in the column or expression.
SELECTstatement includes a
GROUP BYclause, set functions will be applied to groups of values. Columns used for
GROUP BYdo not have to be included in the
Find the number of rows in each category within the FORMATS table:SELECT category_id, COUNT(*) FROM formats GROUP BY category_id;
Restrictions When Using GROUP BY
GROUP BYclause places some restrictions on the
Only constants, columns listed in the
GROUP BYclause, and columns used as arguments to set functions may be included in the
A derived table can be used to overcome this restriction.
Find the number of released items, grouped by year, month and format:select y, m, format, count(*) from ( select extract(year from release_date) as y, extract(month from release_date) as m, format from product_details ) group by y, m, format;
For grouping purposes, null values are regarded as equivalent. Thus for the example table:
The following statement:SELECT sample, COUNT(*) as number ... GROUP BY sample;
Mimer Information Technology AB
Phone: +46 18 780 92 00