MySQL ORDER BY clause

Source: Internet
Author: User

1. Syntax: Select field list from table name [WHERE clause][group by clause][having clause][order by clause];

Annotations:

1. The default is to start with the first record ascending,

2.desc is descending from the first record

3.order by the back can be followed by the aggregation function

Example:

1. Check the average salary for each city and sort in descending order

Statement: Select City,avg (Salary) from student group by City order by AVG (salary) desc;

Annotations:

1. You can sort by using multiple fields at the same time, preferably by specifying a collation when sorting. The first field can compare the results, then the second field is not considered, otherwise the second field value is compared when the first field value is equal.

MySQL ORDER BY clause

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.