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

What is the order in which sql keywords are executed

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

Share

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

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.

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: 0

*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

Database

Wechat

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

12
Report