排序查询
声明:mysql 总结之路是在b站上观看视频进行总结的,mysql 在我上大学的时候已经学过了,同时也学过sql server了,本次总结看看自己能不能温故知新,让自己更加快速的成长。
案例 查询员工信息,要求工资从高到低
select * from employees order by salary desc; #倒叙
案例2 查询部门编号>=90的员工信息,按入职时间的先后经行排序
select * from employees where department_id >=90 order by hiredate asc;
案例3 按表达式排序 按年薪的高低显示员工的信息与年薪
select *,salary *12 *(1+ifnull(commission_pct,0)) as '年薪' from employees
order by salary *12 *(1+ifnull(commission_pct,0)) desc;
案例4:按别名排序 按年薪的高低显示员工的信息与年薪
select *,salary *12 *(1+ifnull(commission_pct,0)) as '年薪' from employees
order by '年薪' desc;
案例5 查询 按姓名的长度显示员工姓名和工资【按函数排序】
select length(last_name) as '字节长度', last_name,salary from employees
order by length(last_name) desc;
案例6 查询员工信息,要求先工资排序,在按员工排序【多个字段排序】
select * from employees order by salary asc,employee_id desc;
order by 子句一般是放在查询语句的最后面,limit子句除外。