Sort query
syntax:
select query field 1
from the table
where [Filters]
order by 2 asc field you want to sort in ascending, desc descending to ascending row field 3 asc, desc descending order
if you do not write the default is ascending
Case: query employee information, salary requirements listed in the order
SELECT
*
FROM
employees
ORDER BY salary DESC;
Case # 2: Query department number> = 90, according to the entry date in ascending order of employee information
SELECT
*
FROM
employees
WHERE
department_id >=90
ORDER BY hiredate ASC;
Case #: Sort by expressions, such as by showing annual salary level
SELECT
salary*12*(1+IFNULL(commission_pct,0))
FROM
employees
ORDER BY salary*12*(1+IFNULL(commission_pct,0)) DESC;
# Case: the sort field aliases, and then sorted by Alias
SELECT
salary*12*(1+IFNULL(commission_pct,0)) AS 年薪
FROM
employees
ORDER BY
年薪 ASC;
Case #: display in descending order according to the length of the name of the employee names and salaries (ordered function)
the SELECT LENGTH ( 'aaaa'); # display length of 4
SELECT
LENGTH(last_name) AS 字节长度,
last_name,
salary
FROM
employees
ORDER BY
LENGTH(last_name) DESC;
Case #: query employee information, press the required wage sorted, then sort the employee number, (sort by multiple fields)
SELECT
*
FROM
employees
ORDER BY
salary ASC,employee_id DESC;