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

Implementation of Docker private library

Installing and deploying a private Docker Registr...

Deploy Nginx+Flask+Mongo application using Docker

Nginx is used as the server, Mongo is used as the...

VSCode+CMake+Clang+GCC environment construction tutorial under win10

I plan to use C/C++ to implement basic data struc...

JS implements random roll call system

Use JS to implement a random roll call system for...

CSS3 transition to achieve underline example code

This article introduces the sample code of CSS3 t...

Summary of Binlog usage of MySQL database (must read)

I won't go into details about how important b...

What to do if the container started by docker run hangs and loses data

Scenario Description In a certain system, the fun...

MySQL index cardinality concept and usage examples

This article uses examples to explain the concept...

Do you know how to use vue-cropper to crop pictures in vue?

Table of contents 1. Installation: 2. Use: 3. Bui...

A brief discussion on the mysql execution process and sequence

Table of contents 1:mysql execution process 1.1: ...

How to enable or disable SSH for a specific user or user group in Linux

Due to your company standards, you may only allow...

How to install and use Server-U 14 version

Introducing Server-U software Server-U is a very ...

Split and merge tables in HTML (colspan, rowspan)

The code demonstrates horizontal merging: <!DO...

Use docker to deploy tomcat and connect to skywalking

Table of contents 1. Overview 2. Use docker to de...