假设有一张employee表。内有ID和工资salary字段。
现在需要得到员工们的最大的工资数值。
使用select max(salary) from employee即可。
但现在我需要在列出最大工资的同时也显示该工资所属的员工ID号,我该怎么写SQL语句?
也就是得到如下结果:
ID     MAX(salary)
XXX    XXXX
问题看上去感觉应该挺简单,但是就是想不起来该怎么写。
谢谢

解决方案 »

  1.   

    select id from employee where salary = (select max(salary) from employee)我只会这个办法了
      

  2.   

    SQL> select * from aa;        ID     SALARY
    ---------- ----------
            10       1000
            20       2000
            25       3000
             5       5000
             8       5000SQL> select id,salary from aa where salary=(select max(salary) from aa);        ID     SALARY
    ---------- ----------
             5       5000
             8       5000
      

  3.   

    如果只要一条记录 
    SQL> select id,salary from (
      2  select id,salary from aa order by salary desc)
      3  where rownum=1;        ID     SALARY
    ---------- ----------
             5       5000