Complete execution sequence of SQL select statements

Source: Internet
Author: User

1. The from clause assembles data from different data sources;
2. The WHERE clause filters record rows based on specified conditions;
3. The group by clause divides data into multiple groups;
4. Use Aggregate functions for computation;
5. Use the having clause to filter groups;
6. Calculate all expressions;
7. Use order by to sort the result set.

For example, in the student renewal table (temporarily recorded as tb_grade), group the records whose "examinee name" is not empty by "examinee name" and filter the grouping results, select a score greater than 600 for the "Total score.
The standard order SQL statement is:
Select candidate name, max (total score) as Max total score
From tb_grade
Where examinee name is not null
Group by candidate name
Having max (total score)> 600
Order by Max total score
In the preceding example, the SQL statement execution sequence is as follows:
(1) first, execute the from clause to assemble data from the tb_grade table.
(2) execute the WHERE clause to filter data that is not null in the tb_grade table.
(3) execute the group by clause to group the tb_grade table by the "Student name" column.
(4) Calculate the max () Aggregation Function and calculate the maximum values in the total score by "total score ".
(5). Execute the having clause to filter course scores 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.