Jump to content

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


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

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.