有以上表结构和 数据,查最新的以currency 分组的数据。需求示例:
如我需要取currency  in (1,2,3) 的最新记录,应返还 图中最后三条。万分感谢

解决方案 »

  1.   

    select * from tt a where exists(select 1 from tt where a.currency=currency and a.creationtime<creationtime) and a.currency in(1,2,3)
      

  2.   

    select * from tt a where not exists(select 1 from tt where a.currency=currency and a.creationtime<creationtime) and a.currency in(1,2,3)
      

  3.   


    你的sql 是可行的自己刚琢磨写了一条。貌似可行。
    SELECT * FROM exchangerate e WHERE currency IN (1,2,3) 
    AND creationTime = (SELECT MAX(creationTime) FROM exchangeRate AS e2 WHERE e2.currency=e.currency )
      

  4.   

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