有一张表test,内容如下:
NLSN   NHDXH SDFXM     SDFHMHZ                          SDFXXK
1031 87                                    0
1031 88                                    0
1031 242 房晓华                                    1
1031 242 王夷                                    1
1031 242 黄苏林                                    4
1031 243                                    0
1031 245 wangjj                                    2
1031 245 test                                    5
1031 246                                    0
1031 250                                    0
1031 272 潘其 王志国:15295185414:320405197411240210    21
1031 272 潘琪 刘露建:13626243315:320405197612240217    21
1031 272 潘琪                                    22 要求:需要统计出nlsn,nhdxh唯一,且sdfxxk的值为最小的仅一条记录,运行sql后结果如下:
NLSN   NHDXH SDFXM     SDFHMHZ                          SDFXXK
1031 87                                    0
1031 88                                    0
1031 242 房晓华                                    1
1031 243                                    0
1031 245 wangjj                                    2
1031 246                                    0
1031 250                                    0
1031 272 潘其 王志国:15295185414:320405197411240210    21请高手赐教。

解决方案 »

  1.   

    select * from 
    (
      select nlsn,nhdxh,sdfxm,sdfhmhz,sdfxxk,
         row_number() over(partition by nlsn,nhdxh order by sdfxxk ) r1
      from tablename
    ) t
    where r1 = 1
      

  2.   


    select NLSN, NHDXH, min(SDFXM)
    from test
    group by (NLSN, NHDXH)
      

  3.   

    哥们你是好久没接触oracle  应该晓得用分析函数 not exixts来弄
      

  4.   

    -- 错了,漏了 SDFHMHZ SDFXXK 两个字段。
    select NLSN, NHDXH, min(SDFXM),SDFHMHZ, SDFXXK
    from test
    group by (NLSN, NHDXH, SDFHMHZ, SDFXXK)
    大虾们,这样写行吗?
      

  5.   

    select * from  
    (
      select nlsn,nhdxh,sdfxm,sdfhmhz,sdfxxk,
      row_number() over(partition by nlsn,nhdxh order by sdfxxk ) rn
      from test
    ) t
    where t.rn = 1
      

  6.   


    --用分析函数来做比较方便,个人意见
    SELECT NLSN, NHDXH, SDFXM, SDFHMHZ, SDFXXK
    FROM (
        SELECT NLSN, NHDXH, SDFXM, SDFHMHZ, SDFXXK,
        Row_Number()over(PARTITION BY NLSN, NHDXH ORDER BY SDFXXK )  rn
        FROM test
    )
    WHERE rn=1;
      

  7.   

    --分析函数 聚合在连接,not exists等select nlsn,nhdxh,sdfxm,sdfhmhz,sdfxxk
    from (select nlsn,nhdxh,sdfxm,sdfhmhz,sdfxxk,
    row_number() over(partition by nlsn,nhdxh order by sdfxxk,rowid) rn
    )
    where rn=1