Where,group By,having,order by execution order and write order

Source: Internet
Author: User

When a query statement appears with Where,group By,having,order by, the order of execution and the order of writing
COUNT (*) is still evaluated when a column appears with a null value using count (column name), but count (column name) does not.

Ii. data Groupings (group by):
Select column A, aggregate function (aggregate function specification) from indicates where filter condition group BY column A
The GROUP BY clause is also used in conjunction with the WHERE Condition statement. When combined, where is the former, group by is behind. That is, the collection of records for select XX from xx is filtered first with the where, and then grouped by the filtered results using GROUP BY.

Third, using the HAVING clause to filter the results after grouping, the syntax is similar to where: having conditional expression

Note the usage differences between having and where:
1.having can only be used after group by to filter the grouped results (that is, to use a having conditional is grouped).
2.where must be before the group by, that is, before having.
Aggregate functions are not allowed in conditional expressions after 3.where, and having can.

Iv. when a query statement appears with Where,group By,having,order by, the order of execution and the sequence of writes are:
1. Executes where XX filters the whole table data, and returns the 1th result set. 2. Returns the 2nd result set for the 1th result set using GROUP by grouping.
3. Select xx is executed for each of the 1 sets of data in the 2nd result set, and several sets are executed several times, returning the 3rd result set.
4. The 4th result set was filtered for the implementation of having XX for the 3rd compilation. 5. Sort for the 4th result set.

———————————————————————————————————————————————-

Group BY and having, Where, and order by these keywords are executed in the following sequence: where, Group by, having, and ordering by.
———————————————————————————–

A superficial understanding of the words,
The syntax order of SELECT is the order of execution

From
WHERE (First filter Tanku/view/result set, then join)
GROUP by
Having (where filtering is a row, having a filtered group, so after group)
ORDER BY

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.