Can Multiple Columns Be Used in GROUP BY

Q

Can Multiple Columns Be Used in GROUP BY? - Oracle DBA FAQ - Understanding SQL SELECT Query Statements

✍: FYIcenter.com

A

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(*) 
  2  FROM employees GROUP BY department_id,
  3  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
......

2007-04-20, 4832👍, 0💬