遇到了一个问题,该表里一个人有好多重复数据。我想取他们各自的最新时间段数据,该怎么写这个语句;表a 字段b 字段c(时间)
        1,   20110221
        1,   20111123
        1,   20120103
        2,   20111212
        2,   20111023
        ……这样的情况,该怎么解决。

解决方案 »

  1.   

    select 字段b,max( 字段c) from 表a group by 字段b
      

  2.   

    select b,max(c) from  a group by b
      

  3.   

    查出来这些数据后,我想要这些数据的整个内容。如果仅仅select b,max(c) from a group by b这样写,并不能查出所有的字段。
      

  4.   

    select * from tb t where not exists(select 1 from tb where b=t.b and c>t.c)
      

  5.   

    试试
    select * 
    from(select a.*,
                row_number()over(partition by b order by c desc) rn 
                from a) 
    where rn=1