各位用户为了找寻关于mysql按照时间分组查询的语句的资料费劲了很多周折。这里教程网为您整理了关于mysql按照时间分组查询的语句的相关资料,仅供查阅,以下为您介绍关于mysql按照时间分组查询的语句的详细内容
mysql 按年、月、周、日分组查询
1.按照年份分组查询
? 1select
date_format(t.bill_time,
'%y'
) month_time,
sum
(t.pay_price) total
from
f_bill t
group
by
month_time;
查询结果
2.按照月份分组查询
? 1select
date_format(t.bill_time,
'%y-%m'
) month_time,
sum
(t.pay_price) total
from
f_bill t
group
by
month_time;
查询结果
3.按照周分组查询
? 1select
concat(substr(date_format(t.bill_time,
'%y-%u'
)
from
1
for
4),
'第'
,substr(date_format(t.bill_time,
'%y-%u'
),6),
'周'
) week_time,
sum
(t.price) total
from
f_bill t
group
by
week_time;
查询结果
4.按照日分组查询
? 1select
date_format(t.bill_time,
'%y-%m-%d'
) month_time,
sum
(t.pay_price) total
from
f_bill t
group
by
month_time;
查询结果
到此这篇关于mysql按照时间分组查询的文章就介绍到这了,更多相关mysql分组查询内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!
原文链接:https://www.cnblogs.com/zhangLiGang/p/15398067.html