标签:显示 函数 信息 HERE esc 先后 部门 desc name
#排序查询
/*
语法:select 查询列表 from 表 [where 筛选条件] order by 排序序列 [asc/desc]
*/
SELECT * FROM employees ORDER BY salary DESC; #默认是asc(升序)
#查询部门编号>=90的员工信息,按入职时间的先后排序
SELECT * FROM employees WHERE department_id>=90 ORDER BY hiredate ASC;
#按年薪的高低显示员工的信息和年薪
SELECT *,salary*12*(1+IFNULL(commission_pct,0)) 年薪 FROM employees ORDER BY 年薪 DESC;
#按姓名的长度显示员工的姓名和工资(按函数排序)
SELECT LENGTH(last_name) 字节长度,last_name,salary FROM employees ORDER BY LENGTH(last_name) DESC;
#查询员工信息,要求先按工资升序排序,再按员工编号降序排
SELECT * FROM employees ORDER BY salary ASC, employee_id DESC;
#查询邮箱有e的员工信息,按邮箱字节长度降序排序,然后按部门编号排序
SELECT * FROM employees WHERE email LIKE ‘%e%‘ ORDER BY LENGTH(email) DESC, department_id ASC;
标签:显示 函数 信息 HERE esc 先后 部门 desc name
原文地址:https://www.cnblogs.com/enoch-m/p/12539145.html