What Are Group Functions?
Page 1 of 1
What Are Group Functions?
Group functions are functions applied to a group of rows. Examples of group functions are:
COUNT(*) - Returns the number of rows in the group.
MIN(exp) - Returns the minimum value of the expression evaluated on each row of the group.
MAX(exp) - Returns the maximum value of the expression evaluated on each row of the group.
AVG(exp) - Returns the average value of the expression evaluated on each row of the group.
How To Use Group Functions in the SELECT Clause?
If group functions are used in the SELECT clause, they will be used on the rows that meet the
query selection criteria, the output of group functions will be returned as output of the query. The
following select statement returns 4 values calculate by 4 group functions on all rows of the
"departments" table:
SQL> SELECT COUNT(*), MIN(department_id), MAX(department_id)
FROM departments;
COUNT(*) MIN(DEPARTMENT_ID) MAX(DEPARTMENT_ID)
---------- ------------------ ------------------
27 10 270
COUNT(*) - Returns the number of rows in the group.
MIN(exp) - Returns the minimum value of the expression evaluated on each row of the group.
MAX(exp) - Returns the maximum value of the expression evaluated on each row of the group.
AVG(exp) - Returns the average value of the expression evaluated on each row of the group.
How To Use Group Functions in the SELECT Clause?
If group functions are used in the SELECT clause, they will be used on the rows that meet the
query selection criteria, the output of group functions will be returned as output of the query. The
following select statement returns 4 values calculate by 4 group functions on all rows of the
"departments" table:
SQL> SELECT COUNT(*), MIN(department_id), MAX(department_id)
FROM departments;
COUNT(*) MIN(DEPARTMENT_ID) MAX(DEPARTMENT_ID)
---------- ------------------ ------------------
27 10 270
Similar topics
» Can Group Functions Be Mixed with Non-group Selection Fields?
» Can Multiple Columns Be Used in GROUP BY?
» Can Group Functions Be Used in the ORDER BY Clause?
» How To Apply Filtering Criteria at Group Level?
» How To Count Groups Returned with the GROUP BY Clause?
» Can Multiple Columns Be Used in GROUP BY?
» Can Group Functions Be Used in the ORDER BY Clause?
» How To Apply Filtering Criteria at Group Level?
» How To Count Groups Returned with the GROUP BY Clause?
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
Sun Jan 31, 2010 12:35 am by Micheal
» Accessing tables of other users in SQL
Sun Jan 31, 2010 12:34 am by Micheal
» Grouping commands in SQL
Sun Jan 31, 2010 12:32 am by Micheal
» Operations on Result Sets in SQL
Sun Jan 31, 2010 12:31 am by Micheal
» Subqueries in SQL
Sun Jan 31, 2010 12:30 am by Micheal
» Joining Relations in SQL
Sun Jan 31, 2010 12:28 am by Micheal
» Delete comand in SQL
Sun Jan 31, 2010 12:27 am by Micheal
» Update command in SQL
Sun Jan 31, 2010 12:26 am by Micheal
» Insert command in SQL
Sun Jan 31, 2010 12:23 am by Micheal