Question

is there way where I can get the values of the day but in a 15 minutes interval, how should I do it? I'd want the result to look something like this:

+--------------------+-------+
| Date/Time          | Value |
+--------------------+-------+
| 2014-01-01 8:00:10 |  10   |
| 2014-01-01 8:15:05 |  11   |
| 2014-01-01 8:30:04 |  24   | 
+--------------------+-------+

I was using this query but this gets the data for every hour and now i need the 15 min interval

SELECT x.* 
 FROM my_table x 
 JOIN 
    ( SELECT MAX(dt) max_dt 
        FROM my_table 
       GROUP BY DATE(dt),HOUR(dt)
    ) y
   ON y.max_dt = x.dt;
Was it helpful?

Solution

Classify your timestamps by which portion of the hour they fall into (using integer division) then group by that classification. So your inner query will look like:

SELECT MAX(dt) max_dt
FROM   my_table
GROUP  BY DATE(dt), HOUR(dt), MINUTE(dt) DIV 15
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top