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

Storage engine and log description based on MySQL (comprehensive explanation)

1.1 Introduction to storage engines 1.1.1 File sy...

Complete steps to quickly build a vue3.0 project

Table of contents 1. We must ensure that the vue/...

How to build a tomcat image based on Dockerfile

Dockerfile is a file used to build a docker image...

CSS3 achieves cool 3D rotation perspective effect

CSS3 achieves cool 3D rotation perspective 3D ani...

HTML table tag tutorial (13): internal border style attributes RULES

RULES can be used to control the style of the int...

How to process blob data in MySQL

The specific code is as follows: package epoint.m...

MySql Installer 8.0.18 Visual Installation Tutorial with Pictures and Text

Table of contents 1. MySQL 8.0.18 installation 2....

Solution to Ubuntu not being able to connect to the Internet

Problem description: I used a desktop computer an...

MySQL 8.0.22 download, installation and configuration method graphic tutorial

Download and install MySQL 8.0.22 for your refere...

mysql 8.0.18 mgr installation and its switching function

1. System installation package yum -y install mak...

Vue implements a simple shopping cart example

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

Let's talk about the issue of passing parameters to React onClick

Background In a list like the one below, clicking...

A Deeper Look at SQL Injection

1. What is SQL injection? Sql injection is an att...

How to use .htaccess to prohibit a certain IP from accessing the website

Preface For cost considerations, most webmasters ...