Collections:
Use Group Functions in ORDER BY Clause in Oracle
Can Group Functions Be Used in the ORDER BY Clause in Oracle?
✍: FYIcenter.com
If the query output is aggregated as groups, you can sort the groups by using group functions in the ORDER BY clause. The following statement returns how many employees are having the same salary in each department. The group output is sorted by the count in each group in descending order:
SQL> SELECT department_id, salary, count(*)
2 FROM employees GROUP BY department_id,
3 salary HAVING count(*) > 1
ORDER BY COUNT(*) DESC;
DEPARTMENT_ID SALARY COUNT(*)
------------- ---------- ----------
50 2500 5
50 3200 4
50 2800 3
80 10000 3
80 9500 3
50 3100 3
50 2600 3
.....
⇒ Ways to Join Two Tables in a Single Query in Oracle
⇐ Use Multiple Columns in GROUP BY in Oracle
2019-10-27, 2419🔥, 0💬
Popular Posts:
What Is a Parameter File in Oracle? A parameter file is a file that contains a list of initializatio...
How to set the current database in SQL Server? Once you are connected to the SQL Server, you should ...
How To Set Up SQL*Plus Output Format in Oracle? If you want to practice SQL statements with SQL*Plus...
What Happens If the Imported Table Already Exists in Oracle? If the import process tries to import a...
How To Change the Name of a Database User in SQL Server? If you want to change the name of an existi...