我有一张表,里面有号码,时间,以及其他的一些字段,我想根据号码删重,取号码出现时间最大的一整条记录,distinct和max的组合好像只能取两个字段,其他的字段取不出来,想请教下大神这个sql语句要怎么写。

解决方案 »

  1.   

    row_number()over(partition by 号码 order by 时间 desc) rn
    查询的时候使用rn=1,问题就解决了。
      

  2.   

    delete from table where rowid not in (select max(rowid) from table  group by 手机)
      

  3.   

    select *
      from tab_phone_test t
     where t.phone_time in (select max(t1.phone_time)
                              from tab_phone_test t1
                             group by t1.phone_num)