/*
语法:select 查询列表 from 表
where 查询条件 #可选
order by 排序列表1 asc|desc, 排序列表2 asc|desc #(升序|降序 默认升序,可省略)
order by 命令除了limit命令,在其他命令的最后面(limit后面会提到,限制输出的行数,limit 5(只输
出5行),limit 5,5(从第五行开始只输出5行,数据表是从第0行开始的));
*/
案例1:按照员工工资从高到低查询员工信息:
select * from employees order by salary desc;
案例2:查询部门编号>=90的员工信息按员工入职时间的先后排序:
select * from employees
where department_id>=90
order by hiredate;
案例3:按年薪高低显示员工信息和年薪(按表达式排序):
select *,salary*12*(1+ifnull(commission_pct,0)) (AS) 年薪 from employees
order by salary*12*(1+ifnull(commission_pct,0));
案例4:按年薪高低显示员工信息和年薪(按别名排序):
select *,salary*12*(1+ifnull(commission_pct,0)) (AS) 年薪 from employees
order by 年薪;
案例5:按姓名长度显示员工姓名和工资(按函数排序):
select last_name,salary from employees order by lenth(last_name);
案例6:查询员工信息,要求先按工资,再按员工编号排序:
select * from employees order by salary asc,emploee_id desc;