得到各部门工资最高员工的员工号员工号 工资   部门代号
1001  1000 1
1002  1020 1
1003  3500 2
1004  3500 2
1005  3600 2上面的表要得到下面的结果,用一个SQL语句怎么实现:员工号 工资   部门代号
1002  1020 1
1005  3600      2

解决方案 »

  1.   


     select 员工号, max(工资)as '工资' ,部门代号 
     from t
     group by  员工号,部门代号 
      

  2.   

    select 员工号,部门,max(工资) as 最高工资 group by 部门,员工号 
      

  3.   

    select 员工号,a.工资,a.部门代号
    from 工资表 as a,
    (select max(工资) as 工资,部门代号
    from 工资表) as b
    where a.工资=b.工资 and a.部门代号=b.部门代号
      

  4.   

    select 员工号,a.工资,a.部门代号
    from 工资表 as a,
    (select max(工资) as 工资,部门代号
    from 工资表
    group by 部门代号) as b
    where a.工资=b.工资 and a.部门代号=b.部门代号
      

  5.   

    TO:鶴嘯九天 这种方法不行,不能按员工号和部门分组,我是要得到各部门工资最高的那个人的员工号
    ------------- select 员工号 from t a 
     where not exists(select 1 from t where a.部门代号=部门代号 and 工资>a.工资)