1: Statement order of grouping function1 SELECT ... 2 FROM ... 3 WHERE ... 4 GROUP BY ... 5 HAVING ... 6 ORDER BY ... 2. The difference between WHERE and HAVING filter conditionsData source location keyword WHERE Original table ORDER BY statement before WHERE HAVING Grouped result set after ORDER BY statement HAVING Three: Examples#1. Query the maximum age of students in each classSELECT MAX(age),class FROM STU_CLASS GROUP BY CLASS; # 2. Query the maximum age of male and female students in each class SELECT MAX(age), class, sex FROM STU_CLASS GROUP BY class,sex; #3. Query the average age of boys and girls in each class, and the average age is greater than 15 years old SELECT AVG (age), class, sex FROM STU_CLASS GROUP BY class,sex HAVING avg(age) > 15; Four: Note1. Usually, the GROUP BY keyword is used together with an aggregate function. First, the GROUP BY keyword is used to group the records, and then the aggregate function is used to calculate each group. The GROUP BY keyword and aggregate functions are often needed when performing statistics. The above is the detailed content of the detailed explanation of the group by statement of MySQL database group query. For more information about MySQL database statements, please pay attention to other related articles on 123WORDPRESS.COM! You may also be interested in:
|
<<: Install MySQL (including utf8) using Docker on Windows/Mac
>>: Detailed explanation of Grid layout and Flex layout of display in CSS3
Table of contents 1. Parent passes value to child...
The first step is to unzip the compressed package...
Table of contents 1. New II. Modification element...
Table of contents Steps to create TCP in Linux Se...
Table of contents 1. Instructions 2. Modifiers 3....
Table of contents 1. Structural instructions Modu...
Table of contents 1. What does shallow copy mean?...
Aggregate functions Acts on a set of data and ret...
Simulation tables and data scripts Copy the follo...
1 Pull the image from hup docker pull nginx 2 Cre...
Idea imports an existing web project and publishe...
Hash Join Hash Join does not require any indexes ...
How do I download MySQL from the official website...
1. Overview of viewport Mobile browsers usually r...
This article collects the fonts used in the logos...