Order by, group by, and having statements

Source: Internet
Author: User

Order by clause: Order by clause is used to sort the query results. The syntax format is as follows: Order by attribute name [ASC | DESC] [, attribute name [ASC | DESC],...]

For example:

Select * From locan order by branch-name DESC, loan-Number

The group by clause groups tuples based on the values of one or more attributes. Clustering functions can apply to different groups.

Select branch-name sum (balance) as summary from account group by branch-name

Having clauses are mainly used to restrict conditions for groups. The predicates in a having clause take effect only after the group is formed. Therefore, clustering functions can be used in a having clause. Generally, the having clause is only used in the SQL statement of the Group by clause to remove groups that do not meet the specified conditions. For example:

Select branch-name, sum (balance) as summary from account group by branch-name having AVG (balance)> 1200

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.