Oracle基础查询
一、条件查询
-- 条件查询 : select 要查询的数据 from 数据源 where 行过滤条件 order by 排序字段1,排序字段2...;
-- 执行流程 : from --> where --> select -> order by
-- 条件判断运算符 : = < > <= >= != <>
-- 条件连接符 : and or not
-- 区间判断 : 条件1 and 条件2 | between 值1 and 值2(相当于>=与<=)
查询20部门的员工信息
select * from emp where deptno = 20;
查询工资大于1000的员工的姓名,工作岗位,工资,所属部门编号
select ename,job,sal,deptno from emp where sal>1000;
把上述代码进行从小到大排序
select ename,job,sal,deptno from emp where sal>1000 order by sal asc;
--默认升序asc可以不写
select ename,job,sal,deptno from emp where sal>1000 order by sal ;
从大到小排序
select ename,job,sal,deptno from emp where sal>1000 order by sal desc;
查询不在20部门工作的员工信息的三种写法
select * from emp where not deptno = 20;
select * from emp where deptno != 20;
select * from emp where deptno <> 20;
查询员工年薪大于20000的员工名称、岗位、年薪并用两种方式完成
--先过滤后查询
select ename,job,sal*12 from emp where sal*12>20000;
--注意以下写法错误
select ename,job,sal*12 as n from emp where n>20000;
--错误的原因是执行顺序是from-->where-->select所以在select中对列取别名,在where中不认得此别名
--先查询后过滤
select ename,job,sal*12 r from emp;
--数据源可以为表也可以为结果集
select *

本文介绍了Oracle数据库中的条件查询,包括查询特定部门员工、按工资排序、使用ANY/SOME/ALL关键字、模糊查询LIKE以及IN和EXISTS关键字的运用。还详细解释了EXISTS子句的工作原理,它用于判断from后面的数据源中是否存在满足条件的记录。
最低0.47元/天 解锁文章
530

被折叠的 条评论
为什么被折叠?



