当前位置:主页 > 数据库 > Mysql >

mysql 获取规定时间段内的统计数据

时间:2021-07-12 13:30:41 | 栏目:Mysql | 点击:

mysql 获取规定时间段内的统计数据

按年统计

SELECT 
  count(*), 
  DATE_FORMAT(order_info.create_time, '%Y-%m-%d') AS count_by_date 
FROM 
  order_info 
WHERE 
  DATE_FORMAT(order_info.create_time, '%Y') = '2017' 
GROUP BY 
  count_by_date 
ORDER BY NULL 

按月统计

SELECT 
  count(*), 
  DATE_FORMAT(order_info.create_time, '%Y-%m-%d') AS count_by_date 
FROM 
  order_info 
WHERE 
  DATE_FORMAT(order_info.create_time, '%Y-%m') = '2017-04' 
GROUP BY 
  count_by_date 
ORDER BY NULL 

具体变换可以自己根据需求变更

感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

您可能感兴趣的文章:

相关文章