侧边栏壁纸
  • 累计撰写 1,975 篇文章
  • 累计创建 73 个标签
  • 累计收到 20 条评论

目 录CONTENT

文章目录

MySQL按天统计和按月统计

猿哥
2023-04-22 / 0 评论 / 0 点赞 / 111 阅读 / 106 字

需求描述

要对某个表的销量或者数量按照每日、每周、每月进行统计

解决方法

1)按天统计:

select DATE_FORMAT(start_time,'%Y%m%d') days,count(product_no) count from test group by days; 

2)按周统计:

select DATE_FORMAT(start_time,'%Y%u') weeks,count(product_no) count from test group by weeks; 

3)按月统计:

select DATE_FORMAT(start_time,'%Y%m') months,count(product_no) count from test group bymonths; 

MySQL按天统计和按月统计

0
博主关闭了所有页面的评论