mysql obtains statistical data within a specified time period

mysql obtains statistical data within a specified time period

mysql obtains 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 

Statistics by month

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

Thank you for reading, I hope it can help you, thank you for your support of this site!

You may also be interested in:
  • MySQL statement to get all dates or months in a specified time period (without setting stored procedures or adding tables)
  • How to use MySQL DATEDIFF function to get the time interval between two dates
  • Mysql timeline data to obtain the first three data of the same day
  • Detailed explanation of MySQL to obtain statistical data for each day and each hour of a certain period of time
  • MySQL example of getting today and yesterday's 0:00 timestamp
  • mysql gets yesterday's date, today's date, tomorrow's date, and the time of the previous hour and the next hour
  • How to get time in mysql

<<:  js to write the carousel effect

>>:  Detailed installation and use of virtuoso database under Linux system

Recommend

Reasons why MySQL cancelled Query Cache

MySQL previously had a query cache, Query Cache. ...

How to install docker on ubuntu20.04 LTS

Zero: Uninstall old version Older versions of Doc...

jQuery plugin to achieve seamless carousel

Seamless carousel is a very common effect, and it...

Friendly Alternatives to Find Tool in Linux

The find command is used to search for files in a...

How to Clear Disk Space on CentOS 6 or CentOS 7

Following are the quick commands to clear disk sp...

mysql data insert, update and delete details

Table of contents 1. Insert 2. Update 3. Delete 1...

A general method for implementing infinite text carousel with native CSS

Text carousels are very common in our daily life....

Implementation of Nginx load balancing cluster

(1) Experimental environment youxi1 192.168.5.101...

How to build DockerHub yourself

The Docker Hub we used earlier is provided by Doc...

HTML form tag tutorial (5): text field tag

<br />This tag is used to create a multi-lin...

Implementation of MySQL GRANT user authorization

Authorization is to grant certain permissions to ...

jQuery realizes the effect of theater seat selection and reservation

jQuery realizes the effect of theater seat select...

Graphical explanation of the solutions for front-end processing of small icons

Preface Before starting this article, let’s do a ...

In-depth explanation of MySQL common index and unique index

Scenario 1. Maintain a citizen system with a fiel...

Detailed explanation of Mysql transaction processing

1. MySQL transaction concept MySQL transactions a...