Jump to content

How do I return a group count for every 15 minutes of the hour on my Table?


BrazilMac

Recommended Posts

Hello all, I have a sql statement that returns a count for every hour on my db, how do I change this so it returns a count for every 15 minutes of the hour?

 

SELECT date_format( timestamp, '%h:00 %p' ) AS HOUR , count( * ) AS mycount
FROM adsense_log
WHERE timestamp LIKE '%2009-01-13%'
GROUP BY DATE( timestamp ) , hour( timestamp )
LIMIT 0 , 30

 

I setup the db so there is a record at each 15 minute interval from 2009-01-13 01:00:00 to 2009-01-13 05:00:00 (total of 20 records).

 

I have tried the following as well:

 

SELECT
DATE_FORMAT(
FROM_UNIXTIME(FLOOR(UNIX_TIMESTAMP(timestamp)/(15*60))*15*60)
, '%Y-%m-%d %h:%m %p') AS HOUR, COUNT(*) AS mycount
FROM adsense_log
WHERE Timestamp BETWEEN  '2009-01-13 00:00:00' AND '2009-01-13 23:59:59'
GROUP BY HOUR LIMIT 0,30;

 

But still groups the count, the resultset still is:

 

HOUR mycount

2009-01-13 01:01 AM 4

2009-01-13 02:01 AM 4

2009-01-13 03:01 AM 4

2009-01-13 04:01 AM 4

2009-01-13 05:01 AM 4

 

Thanks

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.