Execution sequence of select statements in SQL Server

Source: Internet
Author: User

Maybe we will not know the order of the keywords in the SQL statement writing process, and let us take it for fun. In this way, we may be happy at the end, however, our computer is not happy. We need to reschedule our messy SQL statements to achieve the expected results ~~~~~~ Let's take a look at the standard SQL parsing sequence to make our machines more happy and to make SQL statements more professional and practical !!

 

Standard SQL statement sequence:

1) from clause: Assemble data from different data sources. 2) on clause: Filter statements that do not meet the conditions, and then calculate statements that meet the conditions. 3) join clause: query data from these tables based on the relationship between columns in two or more tables. 4) WHERE clause: filter records based on the conditions we have set. 5) grouble by clause: divide data into two or more groups. 6) with cube or with rollup integrated function: Computing. 7) having statement: Screening group. 8) calculation expression. 9) order: sort the results 10) top words: specify the number of returned records. Example: In the student renewal table (temporarily marked as tb_grade), group the "examinee name" and filter the grouping results, select a person with a total score greater than 600. Therefore, the standard SQL statement is: Select examinee name, max (total score) as Max total score form tb_grade where examinee name is not null group by examinee name having max (total score)> 600 order by Max: in the preceding example, the SQL statement is executed in the following order: 1) execute the from statement and assemble data from the data source in the tb_grade table. 2) execute the where statement, filter data that is not null in the Table. 3) execute the group by clause to group the table by "examinee name". 4) Calculate the max () clustering function and evaluate the value by "total score". 5) execute the having statement and filter 6 with a total score greater than 600) Execute the order by statement and sort the final result by "Max total score ".

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.