select 职工号 from 职工 E
  where 工资=(select max(工资) from 职工 as M where M.部门号=E.部门号)

解决方案 »

  1.   

    TRY:
    select 职工号 from 职工 E
    where NOT EXISTS (select 1 from 职工 as M where M.部门号=E.部门号 AND M.工资>E.工资)
      

  2.   

    select 职工号 from 职工 E
    where 工资=(select top 1 工资 from 职工 as M where M.部门号=E.部门号 order by 工资 desc)
      

  3.   

    select 职工号 from 职工 E
      where exists(select * from 职工 as M where M.部门号=E.部门号 and M.工资>E.工资)
      

  4.   

    SELECT 职工号 
    FROM 职工 E
    WHERE NOT EXISTS (SELECT 1 from 职工 WHERE 部门号=E.部门号 AND 工资>E.工资)
      

  5.   

    select 职工号 from 职工 E
    where NOT EXISTS (select 1 from 职工 as M where M.部门号=E.部门号 AND M.工资>E.工资)
      

  6.   

    理论上,用not exists最快的可以试下:
    select E.职工号 from 职工 E left join 职工 M
    on M.部门号=E.部门号 AND M.工资>E.工资
    where M.职工号 is null
      

  7.   

    我的数据库记录太少,看不到查询耗费的时间。能解释一下为什么not exists最快吗?
      

  8.   

    select E.职工号 from 职工 E left join 职工 M
    on M.部门号=E.部门号 AND M.工资>E.工资
    where M.职工号 is null
    是对的
    可是为什么要用where M.职工号 is null啊?
    这块不太明白
    谢谢,给说一下吧