China Naming Network - Ziwei Dou Shu - SQL statement sorting problem

SQL statement sorting problem

You wrote it wrong. When you sort N in descending order according to your writing, the first M ascending order result will be invalid, which means that the last read-only N is in descending order, and your statement itself is redundant.

The correct way to write it is:

SELECT * Select from the orders of m ASC in the north of DESC;

We can analyze the usage of the order by clause through some examples:

Suppose there is an order table:

1, example 1

Display company names in alphabetical order:

Select the company and order number from the orders sorted by company.

The results are as follows:

2. Example 2

Display the company name in alphabetical order and the order number in numerical order:

Select company, order number, order company and order number from the order.

The results are as follows:

3. Example 3

Display company names in reverse alphabetical order:

Select the company and order number from the orders sorted by DESC company.

The results are as follows:

4. Example 4

Display company name in reverse alphabetical order and serial number in numerical order:

SELECT company, OrderNumber FROM Orders ORDER BY company DESC, OrderNumber ASC

The results are as follows:

Note: There are two equivalent company names (W3School) in the above results. Only this time, when the first column has the same value, the second column is arranged in ascending order. The same is true if some values in the first column are empty.