025排序操作
select .. from .. order by 字段 asc/desc
select empno, ename, sal from emp order by sal asc;
asc 不写的话,默认升序
多个字段排序
查询员工的编号、姓名、薪资,按照薪资升序排列,如果薪资相同的,再按照姓名升序排列。
select empno,ename,sal from emp order by sal asc, ename asc;
select empno,ename,sal from emp order by 3 asc, 2 asc;
select ename,job,sal from emp where job in ('MANAGER','SALESMAN') order by sal desc;
select ename,job,sal*12 as yearsal from emp where job in ('MANAGER','SALESMAN') order by yearsal asc;
说明order在select后执行,优先级低
select ename,job,sal*12 as yearsal from emp where job in ('MANAGER','SALESMAN') order by sal asc;
按原始名字sal排序也可