Can Multiple Columns Be Used in GROUP BY?
Page 1 of 1
Can Multiple Columns Be Used in GROUP BY?
You can use multiple columns in the GROUP BY clause as shown in the following example. It
returns how many employees are having the same salary in each department:
SQL> SELECT department_id, salary, count(*)
FROM employees GROUP BY department_id, salary HAVING count(*) > 1;
DEPARTMENT_ID SALARY COUNT(*)
------------- ---------- ----------
90 17000 2
50 3200 4
50 2200 2
50 3600 2
80 10500 2
80 9000 2
50 2700 2
returns how many employees are having the same salary in each department:
SQL> SELECT department_id, salary, count(*)
FROM employees GROUP BY department_id, salary HAVING count(*) > 1;
DEPARTMENT_ID SALARY COUNT(*)
------------- ---------- ----------
90 17000 2
50 3200 4
50 2200 2
50 3600 2
80 10500 2
80 9000 2
50 2700 2
Similar topics
» How To Name Query Output Columns?
» Can the Query Output Be Sorted by Multiple Columns?
» Can Group Functions Be Mixed with Non-group Selection Fields?
» What Are Group Functions?
» Can Group Functions Be Used in the ORDER BY Clause?
» Can the Query Output Be Sorted by Multiple Columns?
» Can Group Functions Be Mixed with Non-group Selection Fields?
» What Are Group Functions?
» Can Group Functions Be Used in the ORDER 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