表结构很简单,有这么几列:人数、时间,现在要取每个小时最后两条数据,mysql中的sql语句该怎么写?如果是sqlserver可以这么实现:
select * from 表 a where 时间 in (select top 2 时间 from 表 where convert(varchar(13),时间,120)=convert(varchar(13),a.时间,120))请各位帮忙

解决方案 »

  1.   

    select * from table a where time in (select time from table goup by hour(time) order by time desc limit 0,2)
    大概是这样,今天没带鼠标,就不给调试了。
      

  2.   

    LS的MYSQL现在还不支持这样的相关子查询。
      

  3.   

    恩,楼上的说得对,提示:
    This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'
    有没有别的变通的办法解决呢?
      

  4.   

    可以把limit作用域部分起新的名称来处理就可以了select * from table a where time in ( select time from (select time from table goup by hour(time) order by time desc limit 0,2) a)