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:
|
<<: Discussion on horizontal and vertical centering of elements in HTML
>>: JavaScript function call classic example code
1. Find a suitable version of redis for docker Yo...
This article shares the specific code of Vue to r...
MySQL storage engine overview What is a storage e...
As the most commonly used layout element, DIV play...
There are many articles about MySQL installation ...
Preface As you know, Linux supports many file sys...
Table of contents Write in front Business code us...
To draw a table in HTML, use the table tag tr me...
This article shares the specific code of JavaScri...
Table of contents 01 Create invisible columns 02 ...
Get a deep understanding of how the Linux configu...
Benefits of a programmatic approach 1. Global con...
MySQL 8 official version 8.0.11 has been released...
Preface This article mainly introduces the releva...
Time always passes surprisingly fast without us n...