SQL SELECT statement Complete order of execution _mssql

Source: Internet
Author: User
1. The FROM clause assembles data from different data sources;
2. The WHERE clause filters the record rows based on the specified criteria;
3. The GROUP BY clause divides the data into multiple groupings;
4, using aggregation function to calculate;
5, using the HAVING clause to filter groupings;
6, the calculation of all expressions;
7. Sort the result set by using order by.

For example: In the Student performance table (Tb_grade), the "candidate name" content is not empty records in accordance with the "candidate name" group, and screening group results, selected "Total score" greater than 600 points.
The standard sequence of SQL statements is:
Select candidate name, Max (total score) as Max Total
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 example above, the SQL statements are executed in the following order:
(1). First execute FROM clause, assemble data source data from Tb_grade table
(2). Executes a WHERE clause to filter all data in the Tb_grade table that is not NULL
(3). Execute GROUP BY clause, Group Tb_grade table by "Student name" column
(4). Compute the MAX () aggregate function and find out the largest number in the total score by "Total Score"
(5). To perform a HAVING clause, the total score of the course is greater than 600.
(7). Execute the ORDER BY clause to sort the final result by "Max score".

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.