How To Divide Query Output into Groups?
Page 1 of 1
How To Divide Query Output into Groups?
You can divide query output into multiple groups with the GROUP BY clause. It allows you specify
a column as the grouping criteria, so that rows with the same value in the column will be
considered as a single group. When the GROUP BY clause is specified, the select statement can
only be used to return group level information. The following script gives you a good GROUP BY
example:
SQL> SELECT department_id, MIN(salary), MAX(salary), AVG(salary)
FROM employees GROUP BY department_id;
DEPARTMENT_ID MIN(SALARY) MAX(SALARY) AVG(SALARY)
------------- ----------- ----------- -----------
100 6900 12000 8600
30 2500 11000 4150
7000 7000 7000
90 17000 24000 19333.3333
20 6000 13000 9500
70 10000 10000 10000
110 8300 12000 10150
50 2100 8200 3475.55556
a column as the grouping criteria, so that rows with the same value in the column will be
considered as a single group. When the GROUP BY clause is specified, the select statement can
only be used to return group level information. The following script gives you a good GROUP BY
example:
SQL> SELECT department_id, MIN(salary), MAX(salary), AVG(salary)
FROM employees GROUP BY department_id;
DEPARTMENT_ID MIN(SALARY) MAX(SALARY) AVG(SALARY)
------------- ----------- ----------- -----------
100 6900 12000 8600
30 2500 11000 4150
7000 7000 7000
90 17000 24000 19333.3333
20 6000 13000 9500
70 10000 10000 10000
110 8300 12000 10150
50 2100 8200 3475.55556
Similar topics
» How To Name Query Output Columns?
» How To Sort the Query Output?
» Can the Query Output Be Sorted by Multiple Columns?
» How To Count Groups Returned with the GROUP BY Clause?
» How To Set Up SQL*Plus Output Format?
» How To Sort the Query Output?
» Can the Query Output Be Sorted by Multiple Columns?
» How To Count Groups Returned with the GROUP BY Clause?
» How To Set Up SQL*Plus Output Format?
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