rt
比如有如下数据表 test我想取得 a字段不重复的最后一项记录 如下用group 只能获取 重复项的 第一条记录 怎么才能获得最后一条记录

解决方案 »

  1.   

    SELECT * FROM TT A WHERE NOT EXISTS(SELECT 1 FROM TT WHERE A.A=A AND A.B<B)
      

  2.   

    select *
    from tb A
    where not exits (select 1 from tb B where A.a=B.a and A.id<B.id)
      

  3.   

    参考下贴中的多种方法http://blog.csdn.net/acmain_chm/article/details/4126306
    [征集]分组取最大N条记录方法征集,及散分....
      

  4.   

    select * from test t1 where (select count(*) from test t2 where t1.a=t2.a and t1.id<t2.id)<1 order by id;