请问下大家,比如说刷选出重复记录了
语句如下 select a.* from  Sheet1$ a inner join 
(select huzhbiha,huwubiha from Sheet1$ group by huzhbiha,huwubiha having count(*)>1) b
on a.huzhbiha=b.huzhbiha and a.huwubiha=b.huwubiha 
where a.huzhbiha='SUNX01' and a.huwubiha='1314-0002-02' 
然后我想在这个结果集的基础上在去除重复记录,重复的记录是不能删除的
也就是相当于刷选出的数据,我只要1条,还是以huzhbiha 和huwubiha 这2个字段刷选
条件,请问高手如何写啊~!

解决方案 »

  1.   

    select distinct a.* from ....
      

  2.   


    with ct1 as
    (
    select a.* from Sheet1$ a inner join  
    (select huzhbiha,huwubiha from Sheet1$ group by huzhbiha,huwubiha having count(*)>1) b
    on a.huzhbiha=b.huzhbiha and a.huwubiha=b.huwubiha  
    where a.huzhbiha='SUNX01' and a.huwubiha='1314-0002-02' 
    )select *
    from ct1 t
    where not exists (select 1 from ct1 where huzhbiha = t.huzhbiha and huwubiha = t.huwubiha and id > t.id)  --或者日期什么的
      

  3.   


    select * from
    (
    select row_number() over (partition by huzhbiha,huwubiha order by huzhbiha) as rowindex,*
    (
    select a.* from Sheet1$ a inner join 
    (select huzhbiha,huwubiha from Sheet1$ group by huzhbiha,huwubiha having count(*)>1) b
    on a.huzhbiha=b.huzhbiha and a.huwubiha=b.huwubiha 
    where a.huzhbiha='SUNX01' and a.huwubiha='1314-0002-02' 
    )t1
    )t2
    where rowindex = 1
      

  4.   

    ;with f as
    (
    select a.* from Sheet1$ a inner join  
    (select huzhbiha,huwubiha from Sheet1$ group by huzhbiha,huwubiha having count(*)>1) b
    on a.huzhbiha=b.huzhbiha and a.huwubiha=b.huwubiha  
    where a.huzhbiha='SUNX01' and a.huwubiha='1314-0002-02' 
    )select
     *
    from
     f t
    where
     id=(select max(id) from f where huzhbiha = t.huzhbiha and huwubiha = t.huwubiha )  --或者日期什么的