我有一个表:
   nsrsbh         rq
  123             14-1月-2009 13:10  
  123             25-6月-2009 15:45
其中 nsrsbh是文本,rq是日期格式,我想把 nsrsbh中重复的都删除点,
(nsrsbh中重复的数据不定,条数也不定)
rq中的数据随便选个都可以,请问应该怎么写sql语句??
得到的结果可以是
nsrsbh         rq
  123             14-1月-2009 13:10  
也可以是
nsrsbh         rq
    123             25-6月-2009 15:45

解决方案 »

  1.   

    delete a from #T a where  exists(select 1 from #T where Name=a.Name and ID<a.ID)
      

  2.   

    delete 
      t
    from
      tb t
    where  exists(select 1 from tb where nsrsbh=a.nsrsbh and rq<a.rq)
      

  3.   


    delete t
    from tb
    where rq not in 
    (select max(rq) from [tb] where nsrsbh=t.nsrsbh)
      

  4.   

    --修改下
    delete 
      t
    from
      tb t
    where  exists(select 1 from tb where nsrsbh=a.nsrsbh and rq<t.rq)
      

  5.   

    delete t
    from tb t
    where rq not in 
    (select max(rq) from [tb] where nsrsbh=t.nsrsbh)
      

  6.   

    delete from 有一个表 a where rq != (select max(rq) from 有一个表 where nsrsbh=a.nsrsbh)
      

  7.   

    --保留同nsrsbh最小的rq
    delete tb from tb t where rq not in (select min(rq) from tb where nsrsbh = t.nsrsbh)--保留同nsrsbh最大的rq
    delete tb from tb t where rq not in (select max(rq) from tb where nsrsbh = t.nsrsbh)
      

  8.   

    delete from 表 where rq not in 
    (select max(rq) from 表 where nsrsbh ='123' ) where nsrsbh ='123'