简体   繁体   English

在MySql中,我如何在过去的一个小时内每60条肠子拉血

[英]In MySql how do I pull every 60 enteries in the last hour

I programmed a hardware monitor that saves select data to a mysql database every second which I realize is overkill, my bose wanted it every 100th of a second and I wanted it every 10 seconds, that was the compromise. 我编程了一个硬件监视器,该监视器每秒钟将选择的数据保存到mysql数据库中,这我认为是过头的,我的bose每100秒要一次,而我每10秒钟要一次,这就是折衷方案。 It's indexed and searching surprisingly much quicker than I expected for such a denormalized database. 对于这样的非规范化数据库,它的索引和搜索速度比我预期的快得多。 alright so here's the issue. 好吧,这就是问题所在。 I want to retrieve data from every 60 second over the last hour. 我想在过去一个小时内每60秒检索一次数据。 I can query every 60 seconds or I can query the last hour, but I can't query every 60 seconds in the last hour. 我可以每60秒查询一次,也可以查询最近一小时,但是我不能在最近一小时查询每60秒一次。

`SELECT Date, Private, Private 2
 FROM Hardware1
 WHERE Date %60 =1
 ORDER BY Date ASC";`

that gets me results from every 60 seconds but they're broken up oddly 每60秒就会得到一次结果,但结果却奇怪地分解了

| 2014-01-20 17:40:21 | 0.336 |     632 |
| 2014-01-20 17:41:41 | 0.336 |     632 |
| 2014-01-20 17:42:01 | 0.336 |     632 |
| 2014-01-20 17:43:21 | 0.336 |     634 |
| 2014-01-20 17:44:41 | 0.336 |     634 |
| 2014-01-20 17:45:01 | 0.336 |     634 |
| 2014-01-20 17:46:21 | 0.336 |     634 |
| 2014-01-20 17:47:41 | 0.336 |     634 |
+---------------------+-------+---------+

then I have 那我有

`SELECT Date, Private, Private2 
 FROM Miner1 
 WHERE Date >= DATE_SUB(NOW(),INTERVAL 1 HOUR)`

Which shows me data every second for the last hour 这会向我显示最近一小时的每秒数据

| 2014-01-20 17:49:12 | 0.336 |     634 | 
| 2014-01-20 17:49:13 | 0.336 |     634 |
| 2014-01-20 17:49:14 | 0.336 |     634 |
| 2014-01-20 17:49:15 | 0.336 |     634 |
| 2014-01-20 17:49:16 | 0.336 |     634 |
| 2014-01-20 17:49:17 | 0.336 |     634 |
| 2014-01-20 17:49:18 | 0.336 |     634 |
| 2014-01-20 17:49:19 | 0.336 |     634 |
| 2014-01-20 17:49:20 | 0.336 |     634 |
+---------------------+-------+---------+

Help Please I've tried so many different things and I've got a killer headache 帮助请尝试了很多不同的东西,我头疼得厉害

The query that returns all the seconds from the last hour is a good beginning: 从最后一个小时返回所有秒数的查询是一个好的开始:

SELECT Date, Private, Private2 
FROM Miner1 
WHERE Date >= DATE_SUB(NOW(),INTERVAL 1 HOUR) and
      second(Date) = 0;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM