饿虎岗资源网 Design By www.oxmxm.com

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 

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

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

饿虎岗资源网 Design By www.oxmxm.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
饿虎岗资源网 Design By www.oxmxm.com