Say I have a table with two columns: the time and the value. I want to be able to get a table with : for each time get the max values of every next n seconds.
If I want the max value of every next 3 seconds, the following table:
| time | value |
|---|---|
| 1 | 6 |
| 2 | 1 |
| 3 | 4 |
| 4 | 2 |
| 5 | 5 |
| 6 | 1 |
| 7 | 1 |
| 8 | 3 |
| 9 | 7 |
Should return:
| time | value | max |
|---|---|---|
| 1 | 6 | 6 |
| 2 | 1 | 4 |
| 3 | 4 | 5 |
| 4 | 2 | 5 |
| 5 | 5 | 5 |
| 6 | 1 | 3 |
| 7 | 1 | 7 |
| 8 | 3 | NULL |
| 9 | 7 | NULL |
Is there a way to do this directly with an sql query?