已知:数据库 Access 
要求:按部门分组,取每个部门工资排名前3位的员工的资料(按薪水高低排序)。
   不能用循环,一条语句完成.
谢.

解决方案 »

  1.   

    select top 3 EmploeeFile group by depart order by salary
      

  2.   

    to 夏天:
    select top 3 EmploeeFile group by depart order by salary如是这样早就解决了,没有这么简单吧。
      

  3.   

    为什么没这么简单?
    select top 3 * from EmploeeFile group by depart order by salary
      

  4.   

    改一下
    select top 3 * from EmploeeFile  order by depart,salary desc
      

  5.   

    我解决了:SELECT *
    FROM z_class AS a
    WHERE a.autoid in (select top 1 ff.autoid from z_class ff where ff.class_id=a.class_id order by ff.sect_id desc)
    ORDER BY a.class_id, a.sect_id DESC;增加一个 autoid字段。(此语句在access-xp下测试通过)非常感谢大家的讨论,如有效率更高的语句欢迎贴出来。