asmith Posted September 14, 2009 Share Posted September 14, 2009 Hi, I have this table that hold records like posts. Each post (row) have a time that it has been posted in. This time was php time() when recording. I wanna get some stats about posts, Like how many were posted in each day. So I'm thinking about a simple group by and counting the rows. Is it possible to group data that does not have same value but are between value a and b? How would you write a query for that? Thanks for your time Quote Link to comment https://forums.phpfreaks.com/topic/174236-solved-group-by-various-numbers-together/ Share on other sites More sharing options...
kickstart Posted September 14, 2009 Share Posted September 14, 2009 Hi You probably could do a group by a range if you played around with a subselect and a case statement. However probably easiest to format the date (ie, maybe to year and week if you wanted the number of posts per week) and then group by that. Note one minor issue that might cause you a problem if you want to draw a graph from this data. Any time period with no posts will not return 0 but will just have no row, which might confuse any graph class you use. You can code round it in php or play around doing an outer join against another select to return all the date / time ranges you are interested in. All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/174236-solved-group-by-various-numbers-together/#findComment-918583 Share on other sites More sharing options...
asmith Posted September 15, 2009 Author Share Posted September 15, 2009 I got it working. Thanks for the info mate. I wrote the graph myself I also found some useful functions in mysql. Thanks again! Quote Link to comment https://forums.phpfreaks.com/topic/174236-solved-group-by-various-numbers-together/#findComment-918738 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.