Question

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. 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. 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.

`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

| 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

Was it helpful?

Solution

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;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top