Select EMP with max SAL from each DEPT

前端 未结 4 1274
予麋鹿
予麋鹿 2021-01-25 22:38

I´m having a bad time with a SQL query. I´m using oracle default tables:

\'EMP\' TABLE

http://imageshack.us/photo/my-images/850/sinttuloxps.png/

AND

4条回答
  •  粉色の甜心
    2021-01-25 23:36

    The following query will omit duplicate values

    SELECT DEPTNO, MAX(SAL) FROM EMP GROUP BY DEPTNO;
    

    The following query will include the duplicate values

    SELECT * FROM EMP WHERE (DEPTNO,SAL) IN 
    ( SELECT DEPTNO, MAX(SAL) FROM EMP GROUP BY DEPTNO)
    

提交回复
热议问题