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 .....
2019-10-27, 886👍, 0💬
Popular Posts:
How to change the data type of an existing column with "ALTER TABLE" statements in SQL Server? Somet...
What Is a Constant or Literal in SQL Server Transact-SQL? A constant, or data literal, is a symbolic...
How To Create a Simple Stored Procedure in SQL Server Transact-SQL? If you want to create a simple s...
What Are Date and Time Functions in MySQL? MySQL offers a number of functions for date and time valu...
How to download and install SQL Server 2005 Sample Scripts in SQL Server? If you want to learn from ...