Home > Database > Mysql Tutorial > body text

Tutorial on how to obtain statistical data within a specified time period using mysql

小云云
Release: 2018-01-27 14:57:50
Original
2319 people have browsed it

This article mainly introduces the relevant information about mysql obtaining statistical data within a specified time period. Friends who need it can refer to it. I hope it can help everyone.

mysql Get statistical data within a specified time period

Statistics by year


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
Copy after login

Monthly statistics


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
Copy after login

The specific transformation can be changed according to your needs.

Related recommendations:

Statistical database daily data growth

##SQL statement skills: monthly statistics

Oracle Optimization Statistics Histograms

The above is the detailed content of Tutorial on how to obtain statistical data within a specified time period using mysql. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!