Get the App
SLTechnology News&Howtos  ›  Database  › 

What is the order in which sql keywords are executed

Shulou Source: shulou.com Published: 2022-06-01 10:31:30 10月04日 Update

This article is to share with you what is the order of sql keyword execution, the editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.

The order of execution of sql keywords is as follows: first execute from statement, where statement, group by statement, having statement and then order by statement.

[recommended course: MySQL tutorial]

Sql keyword execution order

Example:

Select m.* from (select t. From r from (select id,name,e.username,e.realname from departments d, employees e where d.manager=e.username (+) order by id desc) t where rownum?select m. * (select t.mom rep t.rownum r from (select a dome d from table1 order by a desc) t where rownum

< = ? ) mwhere r >

?

The parsing order of the standard SQL is

(1) FROM clause to assemble data from different data sources

(2) WHERE clause to filter records based on specified criteria

(3) GROUP BY clause, which divides the data into multiple groups

(4) use aggregate function to calculate

(5) use HAVING clause to filter grouping

(6) evaluate all expressions

(7) use ORDER BY to sort the result set

Example

In the student score sheet (tb_Grade), group the records whose "examinee's name" content is not empty according to "examinee's name", and filter the grouping results to select those whose "total score" is more than 600points.

The SQL statement is:

Select examinee name, max (total score) as max total score from tb_Grade where examinee name is not null group by examinee name having max (total score) > 600order by max total score

In the above example, the order in which SQL statements are executed is as follows:

(1) first execute the FROM clause to assemble the data from the data source from the tb_Grade table

(2) execute the WHERE clause to filter all the data in the tb_Grade table that are not NULL

(3) execute the GROUP BY clause and group the tb_Grade table according to the "student name" column.

(4) calculate the max () aggregation function and calculate some of the largest values in the total score according to the "total score".

(5) execute the HAVING clause and screen those with a total score of more than 600.

(6) execute the ORDER BY clause and sort the final results by "Max score".

The above is the order in which sql keywords are executed, and the editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

Tags: Clause assembly total score data sentence order name examinee grouping key words sequence result function student score data source more knowledge article Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Shulou Technology Apple Redmi OPPO Reno