mysql 按年、月、周、日分组查询
1.按照年份分组查询
1
|
select date_format(t.bill_time, '%y' ) month_time, sum (t.pay_price) total from f_bill t group by month_time; |
查询结果
2.按照月份分组查询
1
|
select date_format(t.bill_time, '%y-%m' ) month_time, sum (t.pay_price) total from f_bill t group by month_time; |
查询结果
3.按照周分组查询
1
|
select 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.按照日分组查询
1
|
select 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