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 *