如下数据如何处理?李四 20060101
李四 19980203
王二 20020712
王二 20010911
赵八 20060112
现在只想提取每个人最新的数据如:李四 20060101
王二 20020911
赵八 20060112这个句子怎么写?

解决方案 »

  1.   

    select User,max(GetTime) from tb group by User,GetTime
      

  2.   

    create table #T (name varchar(32),dayNum int)
    insert #T
    select 
    '李四', 20060101
    union all select
    '李四', 19980203
    union all select
    '王二' ,20020712
    union all select
    '王二' ,20010911
    union all select
    '赵八' ,20060112select name,daynum from #T a where daynum in (select max(daynum) from #T where name=a.name)
    drop table #Tname                             daynum      
    -------------------------------- ----------- 
    赵八                               20060112
    王二                               20020712
    李四                               20060101
      

  3.   

    select distinct xingming,Max(cast(nianfen,int)) from renyuan group by xingming