我看过一些过去的帖子,其中有关于每天提取最大值的问题。基于此,我尝试了SELECT ts, MAX(current) FROM mytable WHERE ts > date_add(now(), interval -28 day);
,但我只回了一行,这不是我想要的。
在此表中,ts
是我的时间戳,current
是另一列值。我想获得过去28天内每天的最大current
值。但是,我的current
值每天每30分钟记录到表中。因此,每天有很多ts
个值。这可能是上述查询设计不起作用的原因吗?如果是这样,我该如何修改呢?
以下是我的表格如何显示几行的示例:
+---------------------+--------------+
| ts | current |
+---------------------+--------------+
| 2018-01-20 16:27:10 | 439.37 |
| 2018-01-20 17:00:18 | 378.07 |
| 2018-01-20 17:30:15 | 204.80 |
| 2018-01-20 18:00:16 | 196.50 |
| 2018-01-20 18:30:16 | 179.40 |
| 2018-01-20 19:00:16 | 183.00 |
| 2018-01-20 19:30:16 | 105.00 |