есть таблица с соответствиями времени и текущей температуры
cm_stat(ID, DATETIME, CURTIME)
Запрос
SELECT `cm_stat`.`CURTEMP`, `cm_stat`.`DATETIME`
FROM `cm_stat`
ORDER BY `DATETIME` ASC
На выходе:
Array
(
[CURTEMP] => 27
[DATETIME] => 2017-09-22 13:47:41
)
Array
(
[CURTEMP] => 26
[DATETIME] => 2017-09-22 13:47:41
)
Array
(
[CURTEMP] => 27
[DATETIME] => 2017-09-22 13:48:41
)
Array
(
[CURTEMP] => 27
[DATETIME] => 2017-09-22 13:48:41
)
Array
(
[CURTEMP] => 27
[DATETIME] => 2017-09-22 13:49:41
)
Array
(
[CURTEMP] => 27
[DATETIME] => 2017-09-22 13:49:41
)
Array
(
[CURTEMP] => 27
[DATETIME] => 2017-09-22 13:50:41
)
Array
(
[CURTEMP] => 26
[DATETIME] => 2017-09-22 13:50:41
)
Необходимо сгруппировать диапазонами, зафиксировав дату последнего изменения.
Результат:
Array
(
[CURTEMP] => 27
[DATETIME] => 2017-09-22 13:47:41
)
Array
(
[CURTEMP] => 26
[DATETIME] => 2017-09-22 13:47:41
)
Array
(
[CURTEMP] => 27
[DATETIME] => 2017-09-22 13:50:41
)
Array
(
[CURTEMP] => 26
[DATETIME] => 2017-09-22 13:50:41
)