In SQL, GROUP BY is used to group data in the results of SELECT. Before using GROUP BY, you need to know some important rules.
Filter Groups Excessive use of the HAVING clause for grouping. The HAVING clause supports all WHERE operations. The difference between HAVING and WHERE is that WHERE filters rows, while HAVING is used to filter groups. Another way to understand the difference between WHERE and HAVING is that WHERE filters before grouping, while HAVING filters on a per-group basis after grouping. Grouping and Sorting Generally, when you use the GROUP BY clause, you should also use the ORDER BY clause. This is the only way to guarantee that the data is sorted correctly. The execution order of SQL SELECT statement is:
Let me give you an example. select candidate name, max(total score) as max total score from tb_Grade where candidate name is not null group by candidate name having max(total score) > 600 order by max total score In the above example, the SQL statements are executed in the following order:
Note: If join and on are used, on will be executed before where, then join will be executed, and then where will be executed. Attachment: Aggregate functions in MySQL:
Note: avg() ignores rows with null values, count(*) counts all rows, and count(column) ignores rows with null values Summarize The above is the full content of this article. I hope that the content of this article will have certain reference learning value for your study or work. Thank you for your support of 123WORDPRESS.COM. If you want to learn more about this, please check out the following links You may also be interested in:
|
<<: Detailed graphic explanation of installing MySQL database and configuring Java project on Linux
>>: A brief discussion on the lazy loading attribute pattern in JavaScript
Recently, during the development process, I encou...
The difference between replace into and insert in...
Recently I saw an article on a public account tha...
Well, you may be a design guru, or maybe that'...
WebRTC, which stands for Web Real-Time Communicat...
1. Query speed of two query engines (myIsam engin...
Reference Documentation Official Docker installat...
Transactional Characteristics 1. Atomicity: After...
Preface In project development, there are many wa...
This article records the installation and configu...
A few days ago, when I was working on a requireme...
Table of contents What is NULL Two kinds of NULL ...
There are two versions of MySQL database manageme...
1.fullpage.js Download address https://github.com...
One trick for dealing with this type of error is t...