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