部门ID 员工ID 点数
000001 000001 3000
000001 000002 2000
000002 000001 1000
000002 000003 4000运行完后结果应该是这个样子
员工ID 点数
000001 3000 -->此员工取部门ID为最小的部门ID
000002 2000
000003 4000
====== 有多少个员工ID就显示多少个员工ID谢谢各位大虾了。小弟谢过了。

解决方案 »

  1.   

    不知道行不行?
    select
     a.员工ID, 点数
    from
     table a
    where
      exists(
        select
          distinct b.员工ID
        from
          table b
        where
          b.部门ID = (
             select
                min(c.部门ID)
             from
                table  c
             where
                c.员工ID = b.员工ID
          )
          and b.员工ID = a.员工ID)
      

  2.   

    create table mtest3 (deptId number(10),workUserId number(10),poit number(10));select workuserid,poit
       from(
       select workuserid,poit
          ,row_number()over(partition by workuserid order by deptId ) as rn
       from mtest3
       )
       where rn=1
      

  3.   

    select 员工ID,点数 from
    table t,
    (
    select 员工ID id,min(部门ID) dep_id from table
    group by 员工ID
    ) v
    where t.部门ID=v.dep_id and t.员工ID=v.id