Get the App
SLTechnology News&Howtos  ›  Development  › 

How to understand the group by statement of grouping query in MySQL Database

Shulou Source: shulou.com Published: 2022-06-03 09:33:59 10月03日 Update

This article introduces the relevant knowledge of "how to understand MySQL database group query group by statement". In the operation process of actual cases, many people will encounter such difficulties. Next, let Xiaobian lead you to learn how to deal with these situations! I hope you can read carefully and learn something!

1: Statement order of grouping function 1 SELECT ... 2 FROM ... 3 WHERE ... 4 GROUP BY ... 5 HAVING ... 6 ORDER BY ... II: Difference between WHERE and HAVING filter conditions Data source position keyword WHERE original table Before ORDER BY statement WHERE HAVING Grouped Result Set After ORDER BY statement HAVING III: Example #1. Query the maximum age of students in each class SELECT MAX(age),class FROM STU_CLASS GROUP BY CLASS;#2. Query the maximum age of boys and girls 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 SELECT AVG(age),class,sexFROM STU_CLASSGROUP BY class,sex HAVING avg(age) > 15; 4: Attention

1. Typically, the GROUP BY keyword is used in conjunction with an aggregate function to group records using the GROUP BY keyword and then evaluate each group using the aggregate function. The GROUP BY keyword and aggregate functions are often used in statistics.

COUNT() function: used to count the number of records.

SUM() function: Used to calculate the sum of the values of a field.

AVG() function: Used to calculate the average of the values of a field.

MAX() function: Used to query the maximum value of a field.

MIN() function: The minimum value used for the query field.

"How to understand MySQL database group query group by statement" content is introduced here, thank you for reading. If you want to know more about industry-related knowledge, you can pay attention to the website. Xiaobian will output more high-quality practical articles for everyone!

Tags: Function query statement grouping key keyword field age data maximum database content situation more men and women knowledge statistics original practical minimum Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple Shulou Tech Info Linux Redmi macOS