例如有张A表
id value
1   44
2   44
3   34
4   56
5   44
6   56
7   34我需要的结果是取value的值里面对应的最后一行的信息
id value
5   44
7   34
6   56请问这条SQL语句要怎么写?

解决方案 »

  1.   

    select * from tt a where not exists(select 1 fom tt where a.value=value and a.id<id)
      

  2.   

    参考下贴中的多种方法http://topic.csdn.net/u/20091231/16/2f268740-391e-40f2-a15e-f243b2c925ab.html
    [征集]分组取最大N条记录方法征集,及散分....
      

  3.   

    select * 
    from a t
    where not exists (select 1 from a where value=t.value and id>t.id)
      

  4.   

    select value,max(id)
    from A
    group by value
    效率未必高