oracle
程序员文章站
2022-04-20 23:02:59
...
查询员工信息(编号,姓名,月薪,年薪),按月薪升序排序,默认升序,如果月薪相同,按oracle内置的校验规则排序
select empno,ename,sal,sal*12
from emp
order by sal asc;
查询员工信息(编号,姓名,月薪,年薪),按月薪降序排序
select empno,ename,sal,sal*12
from emp
order by sal desc;
查询员工信息,按入职日期降序排序,使用列名
select empno,ename,sal,hiredate,sal*12 "年薪"
from emp
order by hiredate desc;
order by后面可以跟列名、别名、表达式、列号(从1开始,在select子句中的列号)
列名:
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
原文:http://lsieun.blog.51cto.com/9210464/1847064
踩
(0)
赞
(0)
举报
评论一句话评论(0)
共0条
登录后才能评论!