首页 > 数据库技术 > 详细

Oracle条件查询

时间:2016-09-20 21:14:06      阅读:344      评论:0      收藏:0      [点我收藏+]

--查询各个部门的编号,最高工资,总和,平均工资
--并且按照个部门的总工资进行降序排列
select deptno,max(sal),sum(sal),avg(sal)
from teacher
group by deptno
order by sum(sal) desc
--再增加一个条件 并且 部门人数在10人以上的
select deptno,max(sal),sum(sal),avg(sal)
from teacher
group by deptno
having count(deptno)>20
order by sum(sal) desc


--nvl(E1,E2):如果E1为空,则返回E2,否则返回E1
select nvl(mgrno,0) from teacher
--nvl2(E1,E2,E3):如果E1为空,则返回E3,否则返回E2
select nvl2(mgrno,1000,0) from teacher
--decode(value,表达式1,表达式1对应的值....) 底层就是一个if else if
select decode(mgrno,null,0,2000) from teacher

sql语句的执行顺序
1.from 表
2.where 条件
3.group by 分组 根据列
4.having 分组条件
5.select 01 .列 02.distinct 03.top
6.order by 根据指定的列 进行排序

 

Oracle条件查询

原文:http://www.cnblogs.com/liu-chao-feng/p/5890335.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!