MySQL query statement grouped by time

MySQL query statement grouped by time

MySQL query by year, month, week, day group

1. Query by year group

SELECT DATE_FORMAT(t.bill_time,'%Y') month_time,sum(t.pay_price) total FROM f_bill t GROUP BY month_time;

Query results

2. Query by month group

SELECT DATE_FORMAT(t.bill_time,'%Y-%m') month_time,sum(t.pay_price) total FROM f_bill t GROUP BY month_time;

Query results

3. Query by week group

SELECT CONCAT(SUBSTR(DATE_FORMAT(t.bill_time,'%Y-%u') FROM 1 FOR 4),'第',SUBSTR(DATE_FORMAT(t.bill_time,'%Y-%u'),6),'周') week_time,sum(t.price) total FROM f_bill t GROUP BY week_time;

Query results

4. Query by day group

SELECT DATE_FORMAT(t.bill_time,'%Y-%m-%d') month_time,sum(t.pay_price) total FROM f_bill t GROUP BY month_time;

Query results

This is the end of this article about MySQL group query by time. For more relevant MySQL group query content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • MySql query time period method
  • How to use MySQL DATEDIFF function to get the time interval between two dates
  • How to query date and time in mysql
  • MySql database time series interval query method

<<:  Discussion on horizontal and vertical centering of elements in HTML

>>:  JavaScript function call classic example code

Recommend

Vue implements weather forecast function

This article shares the specific code of Vue to r...

Detailed explanation of storage engine in MySQL

MySQL storage engine overview What is a storage e...

MySql 5.6.36 64-bit green version installation graphic tutorial

There are many articles about MySQL installation ...

How to view the type of mounted file system in Linux

Preface As you know, Linux supports many file sys...

Various correct postures for using environment variables in Webpack

Table of contents Write in front Business code us...

HTML table_Powernode Java Academy

To draw a table in HTML, use the table tag tr me...

Implementing a random roll caller based on JavaScript

This article shares the specific code of JavaScri...

Basic operations on invisible columns in MySQL 8.0

Table of contents 01 Create invisible columns 02 ...

Exploring the Linux Kernel: The Secrets of Kconfig

Get a deep understanding of how the Linux configu...

Sample code for programmatically processing CSS styles

Benefits of a programmatic approach 1. Global con...

How to install and deploy MySQL 8.0 under CentOS8

MySQL 8 official version 8.0.11 has been released...

How to generate Hive table creation statement comment script in MySQL metadata

Preface This article mainly introduces the releva...

MySQL multi-table query detailed explanation

Time always passes surprisingly fast without us n...