简体   繁体   English

在 mysql 中计算 id 或其他周数

[英]Count id's or whatever on weeks in mysql

I have a mysql table with a datetime field.我有一个带有日期时间字段的 mysql 表。 Now, for statistics, I need to count how many entries are done in the weeks, 1st week, 2nd week, ...现在,为了统计,我需要计算一周内完成的条目数,第一周,第二周,......

Weeks are from monday to sunday.周是从星期一到星期日。

For now, my idea is to calculate every monday in php and do a query.现在,我的想法是在 php 中计算每个星期一并进行查询。 But 52 weeks do 52 querys.但是 52 周做 52 次查询。

Is there perhaps another solution just in mysql?在 mysql 中可能还有另一种解决方案吗?

Thanks for your reply's谢谢你的回复

Maybe like this?也许像这样?

SELECT WEEK(event_date, 1), COUNT(*) FROM tbl GROUP BY WEEK(event_date, 1)

More info here: https://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_week更多信息: https : //dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_week

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

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