我想使用下面的查询根据时间戳列每 15 分钟对记录进行一次分组,但前两条记录的差异只有 10 分钟。
导轨代码:
select("DATE_FORMAT(reading_on,'%H:%i') as date,
ROUND(UNIX_TIMESTAMP(reading_on)/(900)) as fif ,
max(power) as total").group("fif").where("imei= #{site}" ).order("fif asc")
MYSQL查询:
SELECT DATE_FORMAT(reading_on,'%H:%i') as date,
ROUND(UNIX_TIMESTAMP(reading_on)/(900)) as fif ,
max(power) as total FROM `clarodetails`
WHERE (imei= 353469040778516)
AND (date(reading_on) between '2012-11-18 00:00:00'
AND '2012-11-18 23:59:59')
GROUP BY fif
ORDER BY fif asc LIMIT 15
输出: