BrazilMac Posted January 14, 2009 Share Posted January 14, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/140756-how-do-i-return-a-group-count-for-every-15-minutes-of-the-hour-on-my-table/ Share on other sites More sharing options...
fenway Posted January 14, 2009 Share Posted January 14, 2009 Please don't use pastebin for small code snippets.... we have code blocks for that. You need to a use a modulus for 15 minutes. Quote Link to comment https://forums.phpfreaks.com/topic/140756-how-do-i-return-a-group-count-for-every-15-minutes-of-the-hour-on-my-table/#findComment-736895 Share on other sites More sharing options...
BrazilMac Posted January 14, 2009 Author Share Posted January 14, 2009 Can anyone help me with a "modulus" I have never heard of such a thing ??? ??? ??? Quote Link to comment https://forums.phpfreaks.com/topic/140756-how-do-i-return-a-group-count-for-every-15-minutes-of-the-hour-on-my-table/#findComment-736906 Share on other sites More sharing options...
fenway Posted January 14, 2009 Share Posted January 14, 2009 Really? Look at the output of the MINUTE() - ( MINUTE() % 15 ). You'll see what I'm getting ta. Quote Link to comment https://forums.phpfreaks.com/topic/140756-how-do-i-return-a-group-count-for-every-15-minutes-of-the-hour-on-my-table/#findComment-737025 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.