-2

I have a mysql table with a datetime field. 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. But 52 weeks do 52 querys.

Is there perhaps another solution just in mysql?

Thanks for your reply's

  • mysql itself does not offer such a function as far as i know. Unless phpmyadmin does these statistic things i would roll with your idea. – Alexander Mar 11 '16 at 22:44

1 Answers1

0

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

obe
  • 7,378
  • 5
  • 31
  • 40