前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Oracle函数学习(单表查询和子查询)

Oracle函数学习(单表查询和子查询)

作者头像
葆宁
发布2019-04-19 10:29:27
8920
发布2019-04-19 10:29:27
举报
文章被收录于专栏:FREE SOLO

–单表查询: –当需要的数据在一张表中,考虑使用单表查询 –多表联合查询: –当需要查询的数据分布在多张表中,考虑使用多表联合 –子查询学习: –使用时机:当查询的筛选条件不明确时,考虑使用子查询。 –单行子查询 –多行子查询

–单行子查询:

–使用时机:筛选条件不明确需要执行一次查询,并且查询结果一个字段并值只有一个 –注意:where子句中允许出现查询语句,该查询语句称为子查询 –使用:select 内容 from 表名 where 字段名 比较运算符 子查询语句 –查询所有比雇员“CLARK”工资高的员工信息 select * from emp where sal>(select sal from emp where ename =‘CLARK’) –查询工资高于平均工资的员工的名字和工资 select ename,sal from emp where sal>(select avg(sal) from emp ) –查询和soctt属于同一部门且工资比他低的员工资料 select * from emp where deptno=(select deptno from emp where ename=‘SCOTT’) and sal<(select sal from emp where ename=‘SCOTT’) –查询工资最高的员工资料 select * from emp where sal=(select max(sal) from emp) –查询职务和scott相同,雇佣时间早的员工信息 select * from emp where job=(select job from emp where ename=‘SCOTT’) and hiredate <(select hiredate from emp where ename=‘SCOTT’) –查询工资比scott高或者雇佣时间早的员工编号和名字 select empno,ename from emp where job=(select job from emp where ename=‘SCOTT’) or hiredate <(select hiredate from emp where ename=‘SCOTT’)

----多行子查询:

代码语言:javascript
复制
 --使用:子查询的结果只有一个字段但是字段有n个值,考虑使用多行子查询,其实就是使用关键字
   --关键字1:any 任意
        --select 内容 from 表名 where 字段名 比较运算符 any 子查询语句
   --关键字2:all 所有
        --select 内容 from 表名 where 字段名 比较运算符 all 子查询语句
   --关键字3:in 表示任意存在,相当于 = any  
        --select 内容 from 表名 where 字段名 in 子查询语句   
        --select 内容 from 表名 where 字段名 not in 子查询语句   
--查询工资高于任意一个CLERK的所有员工信息
 select * from  emp where sal> any (select sal from emp where job='CLERK')
--查询工资高于所有SALESMAN的员工信息
select * from emp where sal> all (select sal from emp where job='SALESMAN')
--查询部门20中同部门10的雇员工作一样的雇员信息
select job from emp where deptno=10
select *from emp where (job='MANAGER' or job='PRESIDENT' or job='CLERK') and deptno=20
select * from emp where job  in (select job from emp where deptno=10) and deptno=20
 select * from emp where job = any (select job from emp where deptno=10) and deptno=20
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2019年03月21日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • –单行子查询:
  • ----多行子查询:
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档