Author: java_wxid back to the Mysql database theory and actual combat # advanced 3: sorting query syntax: select queries list — — — (3) from the table name — — — — — – (1) the where condition (2) the order by sorting list asc | desc; ——————④ Features: 1. Asc represents the ascending order. Ascending is the default behavior and desc stands for descending. The order by clause is usually placed at the end of a query statement.

#1. Simple sorting by single field # example; SELECT * FROM employees ORDER BY salary DESC; #2, sort by expression # example: Query employee id >110's name, number, annual salary, SELECT last_name,employee_id,salary*12*(1+IFNULL(commission_pct,0)) FROM employees WHERE employee_id>110 ORDER BY salary*12*(1+IFNULL(commission_pct,0)); #3, sort by alias Query employee id >110's name, number, annual salary, SELECT last_name,employee_id,salary*12*(1+IFNULL(commission_pct,0)) annual salary FROM employees WHERE employee_id>110 ORDER BY annual salary DESC; SELECT LENGTH(last_name) len,last_name FROM employees ORDER BY len; SELECT last_name (last_name) FROM employees ORDER BY len; Support sorting by multiple fields or multiple expressions SELECT LENGTH(last_name) len,last_name FROM employees ORDER BY len,last_name DESC; SELECT last_name (last_name) FROM employees ORDER BY len,last_name DESC; #1. Query the employee's name and department number and annual salary. SELECT last_name,department_id,salary*12*(1+IFNULL(commission_pct,0)) annual salary FROM employees ORDER BY annual salary DESC,last_name ASC; #2. Select the name and salary of the employee whose salary is not between 8000 and 17,000, SELECT last_name,salary FROM employees WHERE salary NOT BETWEEN 8000 AND 17000 ORDER BY salary DESC; #3. Query employee information in email containing e, and first descending by the number of bytes in email. SELECT * FROM employees WHERE email LIKE '%e%' ORDER BY LENGTH(email) DESC,department_id ASC;Copy the code