在MySQL中,如何返回月份中的星期几? [英] In MySQL, how to return the week of the month?
本文介绍了在MySQL中,如何返回月份中的星期几?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
年份分为12个月.我们可以在四个星期内分解一个月.
The year is divided into 12 months. We can break down a month in four weeks.
在MySQL中,如何返回月份中的星期几? (例如:第一周:2个条目,第二周:5个条目,第三周:3个条目;第四周:8个条目)
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)
使用Week和WeekOfYear不能获得理想的结果,因为函数返回的是星期数YEAR,而不是月份.
Using Week and WeekOfYear not get the desired result because the functions return the week number YEAR, not month.
推荐答案
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.
这篇关于在MySQL中,如何返回月份中的星期几?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文