如何更改下面的查询以获得2小时而不是1
SELECT DATE_FORMAT(x.time,'%Y-%m-%d %H:00:00')
, avg(Ph) avg_Ph
FROM Ph x where time >= NOW() - INTERVAL 1 DAY
GROUP
BY DATE_FORMAT(x.time,'%Y-%m-%d %H:00:00');
答案 0 :(得分:1)
SELECT DATE_FORMAT(FROM_UNIXTIME(FLOOR(UNIX_TIMESTAMP(x.time)/7200)*7200),'%Y-%m-%d %H:00:00') AS `two_hour`
, avg(Ph) avg_Ph
FROM Ph x where time >= NOW() - INTERVAL 1 DAY
GROUP
BY `two_hour`