Jump to content

[SOLVED] Group By Week Day


The Little Guy

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.