mysql 时间按季度分类_Mysql按小时,按日,按周,按月,按季度,按年分组统计数据...

本文介绍了如何使用MySQL中的from_unixtime和相关函数,对时间数据按小时、日、周、月、季度和年进行分组统计,包括查询本年度、季度、月、周的数据以及N天内的数据,提供了详细的SQL示例。
摘要由CSDN通过智能技术生成

按小时:sql

select from_unixtime(create_time,"%Y%m%d%H") as hours,count(id) as counts from table group by hours;函数

按日:spa

select from_unixtime(create_time,"%Y-%m-%d") as days,count(id) as counts from table group by days;unix

按周:code

select from_unixtime(create_time,"%Y-%u") as weeks,count(id) as counts from table group by weeks;orm

按月:字符串

select from_unixtime(create_time,"%Y-%m") as months,count(id) as counts from table group by months;table

按季度:form

select concat(from_unixtime(create_time,"%Y"),floor((from_unixtime(create_time,"%m")+2)/3)) as quarters,class

count(id) as counts from table group by quarters;

按年:

select from_unixtime(create_time,"%Y") as years,count(id) as counts from table group by years;

查询本年度数据:

select * fr

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值