Order by injection sorting

Source: Internet
Author: User

For example, if we want to list the values in the Sales column from large to smallStore_InformationInformation in the table,

Store_InformationTable

Store_name Sales Date
Los Angeles $1500 Jan-05-1999
San Diego $250 Jan-07-1999
San Francisco $300 Jan-08-1999
Boston $700 Jan-08-1999

Let's get,

SELECT store_name, Sales, Date
FROM Store_Information
Order by Sales DESC


Result:

Store_name Sales Date
Los Angeles $1500 Jan-05-1999
Boston $700 Jan-08-1999
San Francisco $300 Jan-08-1999
San Diego $250 Jan-07-1999

In the above example, we use the column name to specify the basis for the order. In addition to the column name, we can also use the column Order (based on the order in the SQL statement ). InSELECTThe first column is 1, the second column is 2, and so on. In the above example, we can use the following SQL statement to achieve the same effect:

SELECT store_name, Sales, Date
FROM Store_Information
Order by 2 DESC

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.