1, the key words commonly used in the query are:
SELECT, from, WHERE, GROUP by, have, ORDER by
Where select and from are required, other keywords are optional.
2, the writing Order of these keywords:
SELECT Field List
From table name
WHERE Record Filter Criteria
Group BY Group Field List
Having group filter criteria
Order By Sort Field List
3, where and having the difference:
Where is the filtering of records, and having is a filter for groups after group by.
Having a group by can only be used after it has been used.
4. GROUP by two roles:
The first effect is to group the records taken from the table in one or more fields;
The second function is to go to the weight and its essence is still grouped.
5, the execution order of these keywords:
From->where->group By->having->select->order by
In particular, say:
From: Retrieving records from a specified data table
WHERE: Filters the retrieved records according to the specified criteria
GROUP BY: Groups The filtered records above by the specified criteria
Having: Filters all groups according to the specified criteria
SELECT: Extracts the field list for the specified query (including aggregated fields, calculated fields, expression fields, and so on) from each grouped record that was filtered in the previous step
ORDER BY: The result set from the previous query is sorted by the sorted field list, and the sort results are output
6, Group By field 1, field 2--first group all records according to Field 1, and then group the results after the group in the same field 2.
7. Order BY field 1, field 2--is sorted by field 1 first, and then by Field 2.
8. Collation Keyword: ASC (ascending, default), DESC (Descending).
9, Count keyword, used as a count. COUNT (*) is the overall count of the candidate datasets, and the Count (field) is the count of a field. If Shang appears with a null value, COUNT (*) counts into the column, and count (field) does not count to that column.
Reference: In the query statement, select from the where group by have order by order of execution, thank you.
Order of execution of keywords in SQL queries