Jump to content

[SOLVED] Group by various numbers together


Recommended Posts

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

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

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.