Jump to content

Recommended Posts

I need to get a count from the database and group them by:

- Monday

- Tuesday

- Wednesday

- Thursday

- Friday

- Saturday

- Sunday

 

I have a field called "date" which is a time stamp, and this is the one I want to group by. I also want to ONLY include the last 30 days in this selection. How can I do that?

Link to comment
https://forums.phpfreaks.com/topic/140620-solved-group-by-week-day/
Share on other sites

SELECT DATE_FORMAT(entryTS, '%a') AS 'Day of Week', count(1) AS 'Count'
FROM test
WHERE entryTS >= DATE_SUB(NOW(), INTERVAL 1 MONTH)
GROUP BY 1
ORDER BY DAYOFWEEK(entryTS)

 

I found this on http://lists.mysql.com/mysql/183242

It provides an explanation there.

Edit:  xtropolis beat me.....  Posting it anyway ;p.

 

ORDER BY DAYOFWEEK(column_name);

 

 

Should do it.

 

 

Oh, and for the 30 days thing....

 

 

WHERE column_name > DATE_SUB(NOW(), INTERVAL 30 DAYS)

 

 

 

 

Or when you said timestamp did you mean unix timestamp?

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.