I have a web task for counting some data inside DB. I must count this data daily, weekly, and monthly.
For weekly, I am still confused to decide which MySQL syntax I should use for this case.
There are two suggestions to resolve this problem: using DAY() or WEEK().
I want this syntax is not limited by a confusing thing. As should declare the first of the month and end of month or start in Sunday or Monday, etc. I want it every time cans for use (but focuses at weekly).
Which is the one that I can use? DAY() or WEEK()?
For the weekly statistics, you need to decide whether you want your weekly statistics to run from Monday to Sunday, or from Sunday to Saturday. Either can be supported.
Ultimately, you’ll probably be grouping by both
YEAR(datefield)andWEEK(datefield, 1). When it comes to sorting monthly, you’ll be grouping byYEAR(datefield)andMONTH(datefield). For the daily statistics, if thedatefieldis stored in aDATEtype, then you can simply group by that; if you have time too, you’ll be grouping the values byYEAR(datefield)andDAYOFYEAR(datefield).