Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
172 views
in Technique[技术] by (71.8m points)

In MySQL, how to return the week of the month?

The year is divided into 12 months. We can break down a month in four weeks.

In MySQL, how to return the week of the month? (Example: first week: 2 entries, second week: 5 entries, third week: 3 entries; fourth week: 8 entries)

Using Week and WeekOfYear not get the desired result because the functions return the week number YEAR, not month.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
FLOOR((DayOfMonth(dateCol)-1)/7)+1

I'd like to make it clear that this is probably not a good way to divide your data - (see the comments), but that this will get you as close as you can get.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...