Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Max and Min salaries along with Employee Name

srikanth bFeb 25 2021

SELECT MAX(ENAME) KEEP (DENSE_RANK FIRST ORDER BY SAL DESC) ENAME,DEPTNO,MAX(SAL) AS HIGH_SAL FROM SCOTT.EMP GROUP BY DEPTNO /* Max salary from each Dept */
image.png
SELECT DEPTNO,MIN(SAL) KEEP (DENSE_RANK FIRST ORDER BY SAL,ENAME) AS LEAST_SAL,MIN(ENAME)KEEP(DENSE_RANK FIRST ORDER BY SAL,ENAME) EMP_LEAST_SAL FROM SCOTT.EMP GROUP BY DEPTNO /* Least salary from each dept */
image.pngCan we achieve by combine these two above two queries to get desired output as
DEPTNO | HIGH_SAL | ENAME | LOW_SAL | EMP_WITH LEAST_SAL

This post has been answered by mathguy on Feb 25 2021
Jump to Answer
Comments
Post Details
Added on Feb 25 2021
5 comments
3,282 views