0

我有:

表信息更新
+-------+-----------+-----------+-----------+--- --------+
| idKey1| idKey2 | __date_Update_ | 日周|
+-------+-----------+------------+-----------+----- ------+
| 1___ | __ 3 __ _ _ | 2013.01.01 15:00:00 | 2 |
| 1___ | __ 3 __ _ _ | 2013.01.01 18:00:00 | 2 |
| 1___ | __ 3 __ _ _ | 2013.01.02 15:00:00 | 3 |
| 1___ | __ 3 __ _ _ | 2013.01.02 18:00:00 | 3 |
| 1___ | __ 3 __ _ _ | 2013.01.03 15:00:00 | 4 |
| 1___ | __ 3 __ _ _ | 2013.01.03 18:00:00 | 4 |
+-------+-----------+------------+-----------+----- ------+

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

选择 * FROM infoUpdate if where date_Update <='2013.01.03 18:00:00';

这就是我正在寻找的:

+-------+-----------+------------+-----------+----- ------+
| idKey1| idKey2 | 日期_更新 | 日周|
+-------+-----------+------------+-----------+----- ------+
| 1 | 3 | 2013.01.01 18:00:00 | 2 |
| 1 | 3 | 2013.01.02 18:00:00 | 3 |
| 1 | 3 | 2013.01.03 18:00:00 | 4 |
+-------+-----------+------------+-----------+----- ------+

4

2 回答 2

1

这对你有用吗

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

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

于 2013-09-14T14:59:09.187 回答
0

它对你有用吗:

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);

如果您只对上周数据感兴趣,DATE(dateUpdate)可以从GROUP BY.

于 2013-09-14T14:53:12.833 回答