简体   繁体   English

按星期几将MySQL数据分组

[英]Grouping MySQL data by which day of the week it is

I'm attempting to separate my database entries into the number of entries that fall on each day of the week (Mon=43, Tue=35...) with no regard for month or year. 我试图将我的数据库条目分成一周中每一天(星期一= 43,星期二= 35 ...)的条目数量,而不考虑月份或年份。 The result from the query below return eight results instead of seven and the number of results for each day is incorrect. 以下查询的结果返回八个结果,而不是七个,并且每天的结果数不正确。

SELECT COUNT(*) FROM table GROUP BY DAYOFWEEK(date)

Example of my table: 我的桌子的例子:

date
07/11/13
07/16/13
07/17/13
07/24/13
07/26/13
07/26/13

Am I using DAYOFWEEK correctly? 我是否正确使用DAYOFWEEK?

I would suggest to change your query as follow: 我建议更改您的查询,如下所示:

SELECT DAYOFWEEK(date), COUNT(*) FROM table GROUP BY DAYOFWEEK(date)

so you can better understand if there's something wrong, anyway: yes you're using dayofweek correctly. 因此无论如何您都可以更好地了解是否出了什么问题:是的,您正确地使用了dayofweek。 I am a bit surprised by the fact that you get 8 results... can you show us the results please? 我得到8个结果让我感到有些惊讶...您能告诉我们结果吗?

Gnagno 格纳尼奥

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM