开发者

Mysql query - group by datetime period in 5 minutes

开发者 https://www.devze.com 2023-02-24 00:14 出处:网络
I have searched all over and can\'t manage to get this to work. I am trying to build a question that groups my records within 5 minutes - and displays the last entry. However I managed to get there ha

I have searched all over and can't manage to get this to work. I am trying to build a question that groups my records within 5 minutes - and displays the last entry. However I managed to get there halfway, but my query is only returning the first entry (XX=10).

I do have the following data:

ID        XX       DATETIME
N1         5       2009-05-01 13:00:00
N1        10       2009-05-01 13:04:49
N2         7       2009-05-02 14:00:00

and I want my group by to give me this:

N1      10
N2       7

I have uses this group by开发者_如何学C statment:

((60/15) * HOUR(created_on) + FLOOR(MINUTE(created_on) / 15)) 

Any one out there that has any ideas on how this query should look like?

Best regards, Joakim


You can simply use: ((60/12) * HOUR(created_on) + FLOOR(MINUTE(created_on) / 5))


UNIX_TIMESTAMP(created_on) - UNIX_TIMESTAMP(created_on) % 5
0

精彩评论

暂无评论...
验证码 换一张
取 消