基于int-dateid(yyyymmdd)的mysql每周分组
我读过一些类似的问题 但是我的日期类型是int(11)(我无法更改结构)来存储类似于20150101的内容,以表示2015年1月1日。我应该如何使用基于此的分组方法 比如:基于int-dateid(yyyymmdd)的mysql每周分组,mysql,sql,Mysql,Sql,我读过一些类似的问题 但是我的日期类型是int(11)(我无法更改结构)来存储类似于20150101的内容,以表示2015年1月1日。我应该如何使用基于此的分组方法 比如: 我认为您需要首先将int(11)值更改为date,然后使用Week函数ie select WEEK(DATE(dateid)) as weeknum, game ,count(*) from table 编辑:- 根据您的意见,您可以尝试使用 select concat('last ' ,(WEEK(dateid,1)
我认为您需要首先将
int(11)
值更改为date
,然后使用Week
函数ie
select WEEK(DATE(dateid)) as weeknum, game ,count(*)
from table
编辑:-
根据您的意见,您可以尝试使用
select concat('last ' ,(WEEK(dateid,1) -WEEK(CURDATE(),1)),' week',' ' )
还要详细检查该功能
WEEK()的两个参数形式允许您指定
一周从星期日或星期一开始,返回值是否应为
在0到53或1到53的范围内。如果mode参数为
省略,使用默认的_week_格式系统变量的值
另请参见此列表以供参考:
M F.day Range Week 1 is the first week …
0 Sunday 0-53 with a Sunday in this year
1 Monday 0-53 with more than 3 days this year
2 Sunday 1-53 with a Sunday in this year
3 Monday 1-53 with more than 3 days this year
4 Sunday 0-53 with more than 3 days this year
5 Monday 0-53 with a Monday in this year
6 Sunday 1-53 with more than 3 days this year
7 Monday 1-53 with a Monday in this year
M = Mode
F.day = First day of week
我不能改变这个世界的结构db@Jaskey:-您不必为此更改结构。我要求您使用FROM_UNIXTIME函数,但我尝试过类似的方法:FROM_UNIXTIME(20150101),它返回1970-08-22 14:15:01…@Jaskey:-更新了我的答案。起初我认为dateid是一个整数。但是你的int列是dateformat,所以你需要一个日期函数。请尝试更新的查询。是的,它应该可以工作。请你更新一下你的答案,这样我会把“上周”作为周数,因为这对其他人更有帮助,我会接受你的答案
M F.day Range Week 1 is the first week …
0 Sunday 0-53 with a Sunday in this year
1 Monday 0-53 with more than 3 days this year
2 Sunday 1-53 with a Sunday in this year
3 Monday 1-53 with more than 3 days this year
4 Sunday 0-53 with more than 3 days this year
5 Monday 0-53 with a Monday in this year
6 Sunday 1-53 with more than 3 days this year
7 Monday 1-53 with a Monday in this year
M = Mode
F.day = First day of week