Jump to content

[SOLVED] Returning results by week


soycharliente

Recommended Posts

I am trying to figure out how to get data on a per week scale. The fields in the table that matter would probably be:

`id` int( NOT NULL auto_increment
`pid` int(4) NOT NULL default '0'
`thedate` date NOT NULL default '0000-00-00'

 

pid is the parent id. (I have another table with locations and corresponding ids.) I would like to count the unique pids (I've used GROUP BY before) in each week since the first entry. I really have no idea where to start. I don't even know if this is possible.

 

I'm not asking for full code. Some sudo-code would be great. I've been thinking about it for a while and don't even know where to begin. Can someone give me a hint in the write direction so I can begin to write some code and come back if it breaks?

 

 

Link to comment
Share on other sites

Edit:  Beaten to it....  Gotta stop opening 10 tabs....

 

 

 

http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html

 

 

WEEKOFYEAR would be what you're looking for.

 

If you plan on doing this on a ton of records, you might want to precalculate the week of the year since it could get expensive, especially if using the field as a constraint or in a group by, which you will be doing.

Link to comment
Share on other sites

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.