MySQL Forums
Forum List  »  Newbie

Re: group by minutes?
Posted by: laptop alias
Date: March 28, 2008 02:20AM

From artfulsoftware:

http://www.artfulsoftware.com/infotree/queries.php

Group data by datetime periods
To group rows by a time period whose length in minutes divides evenly into 60, use this formula:

GROUP BY ((60/periodMinutes) * HOUR( thistime ) + FLOOR( MINUTE( thistime ) / periodMinutes ))

where thistime is the TIME column and periodMinutes is the period length in minutes. So to group by 15-min periods, write ...

SELECT ...
GROUP BY ( 4 * HOUR( thistime ) + FLOOR( MINUTE( thistime ) / 15 ))
...

Options: ReplyQuote


Subject
Written By
Posted
March 28, 2008 12:47AM
Re: group by minutes?
March 28, 2008 02:20AM
March 28, 2008 09:10AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.