Home  >  Article  >  Database  >  Detailed code explanation of how mysql obtains statistical data within a specified time period

Detailed code explanation of how mysql obtains statistical data within a specified time period

黄舟
黄舟Original
2017-05-14 10:02:231394browse

This article mainly introduces mysql Relevant information on obtaining statistical data within a specified time period. Friends in need can refer to

mysql Obtaining statistical data within a specified time period Statistical data

Annual 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') = '2017' 
GROUP BY 
  count_by_date 
ORDER BY NULL

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

The specific transformation can be changed according to your needs

The above is the detailed content of Detailed code explanation of how mysql obtains statistical data within a specified time period. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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