MySql按时间戳获取前几行

MySql按时间戳获取前几行,mysql,Mysql,我有: 表infoUpdate +-------+-----------+-----------+-----------+-----------+ |idKey1 | idKey2 |日期更新| +-------+-----------+-----------+-----------+-----------+ |1_uuuu124;uuu3_uuuuuuuu| 2013.01.01 15:00:00 | 2 | |1_uuuu124;uuu3_uuuuuuu| 2013.01.01 18:00:

我有:

表infoUpdate
+-------+-----------+-----------+-----------+-----------+
|idKey1 | idKey2 |日期更新|
+-------+-----------+-----------+-----------+-----------+
|1_uuuu124;uuu3_uuuuuuuu| 2013.01.01 15:00:00 | 2 |
|1_uuuu124;uuu3_uuuuuuu| 2013.01.01 18:00:00 | 2 |
|2013.01.02 15:00:00 | 3 |
|2013.01.02 18:00:00 | 3 |
|1_uuuu124;uuu3_uuuuuuu| 2013.01.03 15:00:00 | 4 |
|2013.01.03 18:00:00 | 4 |
+-------+-----------+-----------+-----------+-----------+

如何通过时间戳仅获取前几行

选择*FROM infoUpdate,如果其中date_Update是否适用于您:

Select idKey1, idKey2 , DayWeek, MAX(dateUpdate) as dateUpdate
FROM infoUpdate 
where date_Update <='2013.01.03 18:00:00'
GROUP BY idKey1, idKey2 , DayWeek, DATE(dateUpdate);
选择idKey1、idKey2、DayWeek、MAX(dateUpdate)作为dateUpdate
来自infoUpdate
在哪里更新日期对您有效

 Select * FROM infoUpdate  where date_Update >= DATE_SUB( '2013.01.03 18:00:00' ,INTERVAL 90 DAY ) 

这将为您提供上述日期之前90天的记录

从查询中删除
if
。时间戳可能是任何示例2013.01.03 15:00:00?我从问题中复制了时间戳。当然,它可以是任何东西