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
##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.
##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##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?
5. MySQL creates fields + data processing functions + summary data (aggregation functions) + grouped data_MySQL
6. Oracle 11g’s new aggregate function listagg implements column-to-row conversion
7. Oracle Basics Tutorial: Aggregation, Grouping, Row to Column
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!