Get the App
SLTechnology News&Howtos  ›  Database  › 

What is the principle of continuous aggregation in mysql

Shulou Source: shulou.com Published: 2022-05-31 22:30:18 11月11日 Update

Today, I will talk to you about the principle of continuous aggregation in mysql, which may not be well understood by many people. in order to make you understand better, the editor has summarized the following content for you. I hope you can get something according to this article.

Continuous aggregation is the operation of aggregating ordered data in chronological order.

In the following rescue example, you will use the EmpOrders table, which is used to hold the number of orders that occur per employee per month.

Run the following code to create the EmpOrders table and populate the sample data.

CREATE TABLE EmpOrders (empid INT NOT NULL,ordermonth DATE NOT NULL,qty INT NOT NULL,testPRIMARY KEY (empid,ordermonth))

Query the order table and the orderdetails table to insert the monthly order in the EmpOrder table. The sql statement is as follows (the trick is to group by month)

INSERT INTO EmpOrdersSELECT a.employeeidMagorderdate AS Order date,SUM (quantity) AS qtyFROM orders aINNER JOIN orderdetails bON a.orderid=b.orderidGROUP BY employid,DATE_FORMAT (orderdate,'%Y-m')

The following is the php file that generates the sample data

Tags: Data content examples principles employees orders order lieutenant general code skills quantity documents time more knowledge articles industry sentences information information channels Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker vpn NVidia Xiaomi Redmi