1

如何更改下面的查询以获得 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');
4

1 回答 1

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`
于 2013-05-03T07:47:19.320 回答