mysql如何分别按照7天,一个季度 来group by 这个时间阶段的count时间字段存的是regdate
参考百度统计以下是七天一个跨度
以下是一个季度一个跨度
人生最曼妙的风景,竟是内心的淡定与从容!
Map time into numbers, use calculated columns, and then group by
For the quarter, use the month to calculate a new value, and then group by this field(month-1)/4+11 2 3 4 ---> 1
Then, use the week value for 7 days. Mysql has a function to get the month or week number of a certain date regdate.
For example, mongodb has this
db.sales.aggregate( [ { $project: { year: { $year: "$date" }, month: { $month: "$date" }, day: { $dayOfMonth: "$date" }, hour: { $hour: "$date" }, minutes: { $minute: "$date" }, seconds: { $second: "$date" }, milliseconds: { $millisecond: "$date" }, dayOfYear: { $dayOfYear: "$date" }, dayOfWeek: { $dayOfWeek: "$date" }, week: { $week: "$date" } } } ] )
mongodb’s documentationmysql related date functions
Map time into numbers, use calculated columns, and then group by
For the quarter, use the month to calculate a new value, and then group by this field
(month-1)/4+1
1 2 3 4 ---> 1
5 6 7 8 ---> 2
Then, use the week value for 7 days.
Mysql has a function to get the month or week number of a certain date regdate.
For example, mongodb has this
mongodb’s documentation
mysql related date functions