当前位置:Gxlcms > 数据库问题 > Oracle系列:(7)order by子句

Oracle系列:(7)order by子句

时间:2021-07-01 10:21:17 帮助过:93人阅读

列名:

select empno,ename,sal,hiredate,sal*12 "年薪" 
from emp
order by hiredate desc;


别名: 

select empno,ename,sal,hiredate,sal*12 "年薪" 
from emp
order by "年薪" desc;


表达式:

select empno,ename,sal,hiredate,sal*12 "年薪" 
from emp
order by sal*12 desc;


列号,从1开始:

select empno,ename,sal,hiredate,sal*12 "年薪" 
from emp
order by 5 desc;

技术分享


查询员工信息,按佣金升序或降序排列,null值看成最大值

select * from emp order by comm desc;

技术分享

技术分享


查询员工信息,对有佣金的员工,按佣金降序排列,当order by 和 where 同时出现时,order by 在最后

select *
from emp
where comm is not null
order by comm desc;

技术分享


查询员工信息,按工资降序排列,相同工资的员工再按入职时间降序排列

select *
from emp
order by sal desc,hiredate desc;
select *
from emp
order by sal desc,hiredate asc;

注意:只有当sal相同的情况下,hiredate排序才有作用


查询20号部门,且工资大于1500,按入职时间降序排列

select *
from emp
where (deptno=20) and (sal>1500)
order by hiredate desc;

技术分享


下面的字符串‘30‘可以隐式转换为数字

select * from emp where deptno in (10,20,30,50,‘30‘);

技术分享

select * from emp where deptno in (10,20,30,50,‘a‘);

技术分享



Oracle系列:(7)order by子句

标签:oracle

人气教程排行