Home >Database >Mysql Tutorial >Detailed introduction to aggregate functions

Detailed introduction to aggregate functions

伊谢尔伦
伊谢尔伦Original
2017-06-11 09:12:503179browse

As you can see, it is very easy to use. But there are a few rules to be aware of when doing a merge. 1.UNION must be composed of two or more SELECT statements, separated by the keyword UNION (therefore, if 4 SELECT statements are combined, 3 UNION keywords will be used). 2. Each query in a UNION must contain the same columns, expressions, or aggregate functions (although the columns do not need to be listed in the same order). 3. Column data types must be compatible: the types do not have to be exactly the same, but must be a type that the DBMS can convert implicitly (for example, a different numeric type or a different date type). If these basic rules or restrictions are followed, you can use it for any data retrieval task. Including or suppressing duplicate rows We noticed that when executed separately, the first SELECT statement returned 4 rows and the second SELECT statement returned 5 rows. But after combining the two SELECT statements with UNION, only 8 rows were returned instead of 9. UNION automatically removes duplicate rows from the query result set (in other words, it behaves the same as a single SELECT statement

1. Example of UNION collation in MySQL combined query

Detailed introduction to aggregate functions

##Introduction: As you can see, it is very easy to use, but there are a few rules to pay attention to when doing the merge. 1.UNION must be composed of two or more SELECT statements, separated by the keyword UNION (therefore, if 4 SELECT statements are combined, 3 UNION keywords will be used) 2. Each of the UNIONs. The query must contain the same columns, expressions, or aggregate functions (but the columns do not need to be listed in the same order)

##2.

MySQL uses joins with aggregate functions.

Detailed introduction to aggregate functions##Introduction: Aggregate functions are used to summarize data. Although all examples of aggregate functions so far only summarize data from a single Tables summarize the data, but these functions can also be used with joins. To illustrate this, consider an example of retrieving all customers and the number of orders placed by each customer. The following code uses the COUNT() function to accomplish this. This works:

3.

mysql data grouping: Create grouping

Detailed introduction to aggregate functions##Introduction: SQL aggregate functions can be used to summarize data. This allows us to count rows, calculate sums and averages, and obtain maximum and minimum values ​​without retrieving all the data. Performed on all data in the table or data matching a specific where clause. As a reminder, the following example returns the number of products provided by supplier 1003

4. phpHow Output the following MySQL query results using aggregate functions and grouped data?

##Introduction: How to output the following MySQL query results using aggregate functions and grouped data?

5. MySQL creates fields + data processing functions + summary data (aggregation functions) + grouped data_MySQL

Introduction: Part of the text description in this article is transferred from MySQL Must Know, which is intended to review the basic knowledge of MySQL to create field data processing functions, summarize data (aggregation functions), and group data

6. Oracle 11g’s new aggregate function listagg implements column-to-row conversion

Introduction: Oracle 11g’s new aggregate function listagg implements column-to-row conversion. First, the syntax: LISTAGG ( column | expression, delimiter ) WITHIN GROUP (ORDER BY colum

7. Oracle Basics Tutorial: Aggregation, Grouping, Row to Column

Introduction: Multi-line function aggregate function execution order: tName--where--group by --having--order by(select)where The alias in the current clause cannot appear, and aggregation cannot be used

8. MySQL condition optimization example

Introduction: An example of MySQL condition optimization. The HAVING condition can not be incorporated into the WHERE condition under any circumstances. It can only be done if there is no GROUPBY condition or aggregate function in the SQL statement.

9. MySQL data summary and aggregation functions MySQL series (seven)

Introduction: MySQL data summary and aggregation functions - MySQL series (seven) ) 1. Aggregation function Aggregation function is a function that operates on row groups, calculates and returns a single function. SQL aggregate function function description AVG() Returns the average COUNT() of a certain column Returns the number of rows in a certain column MAX() Returns the maximum MIN() of a certain column Returns the minimum SUM() of a certain column Returns the sum of a certain column (1) , AV

##10. GROUPING, ROLLUP and CUBE in SQLServer

Introduction: Aggregation function: GROUPING is used Operators used to summarize data: ROLLUP 1. Use CUBE to summarize data. The result set generated by the CUBE operator is a multidimensional data set. Cubes are an extension of fact data, which is data that records individual events. Extensions are built on the columns the user intends to analyze. These columns are called dimensions. A cube is a result set, which contains

[Related Q&A recommendations]:

mysql - What is the principle of Group By? Will it affect performance if I supplement Groupby's columns to make them consistent with Select's columns (except for aggregate functions)?

The above is the detailed content of Detailed introduction to aggregate functions. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn