八、排序查询
1、语法:
select 列表
from 表名
where 筛选条件
order by 排序列表 (asc/desc) asc是升序 desc是降序 默认的是asc
2、案例:
案例一:查询员工信息,按照工资从高到低
select *
from employees
order by salary desc;
案例二(添加筛选条件):查询部门编号大于90的员工信息,按照入职时间的先后排序
select *
from employees
where department_id > 90
order by hiredate asc;
案例三(按表达式排序):按年薪的高低显示员工信息和年薪
select *,salary*12*(1+ifnull(commission_pct,0)) '年薪'
from emp
order by salary desc;
ifnull(列名,返回值) 若列中有的属性为null,则返回0
案例四:查询员工信息,要求先按工资升序,在按员工编号降序
select *
from emp
order by salary asc,employ_id desc;

浙公网安备 33010602011771号