举例说明
select * from tt a where a.logtime>='2013-10-12'
 and a.logtime<'2013-10-30'
and not exists(select 1 from tt where a.username=username
and a.logtime>logtime)

解决方案 »

  1.   

    时间上加索引
    select *
    from loginlog a
    where logClient='WX_GAME' and a.logtime>='2013-10-12'
    and a.logtime<'2013-10-30'
    and not exists (select 1 from loginlog where A.username=username and A.logtime<logtime and logClient='WX_GAME' and a.logtime>='2013-10-12'
    and a.logtime<'2013-10-30')
      

  2.   

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