Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

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

2025-04-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 259

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report