Oracle 数据库 限制数据和数据排序-第三章

--使用where子句

--比较数值型数据

--1.查询部门编号为10的员工

select * from emp where deptno=10;

--2.查询部门编号不为10的员工

select * from emp where deptno <> 10;

select * from emp where deptno !=10;

--比较字符型数据1.自负使用'' 单引号括起来  2.区分大小写

1.查询职位为'CLERK'的所有员工

select * from emp where job='CLERK';

--比较日期型数据 1.日期使用''单引号括起来    .2.使用dd-MON-RR格式日期  日-月-年

1.查询入职日期为1980/12/17的员工信息

select * from emp where hiredate='17-12月-80';--DD-MON-RR

--特殊比较运算符

--BETWEEN..AND..   判断要比较的值是否在某个范围内

1.查询薪资在2000到3000之间的员工信息

select * from emp where sal between 2000 and 3000;--包括边界值

select * from emp where sal>=2000 and sal<=3000;--同上

2.查询入职日期在82年以后,且在88年之前入职的员工信息

select * from emp where biredate between '31-12月-82' and '31-12月-87';--包括边界值

select * from emp where biredate >='31-12月-82' and '31-12月-87'--同上

--IN 判断要比较的值是否和集合列表中的任何一个值相等

1.查询部门编号为10或20的员工信息

select * from emp where deptno in(10,20);

select * from emp where deptno=10 or deptno=20;--同上

--like运算符:模糊匹配  %代表0个或者任意多个字符   _表示任意一个字符

1.查询雇员姓名以S开头的员工信息

select * from emp where ename like 's%';--匹配S开头的雇员名字

2.查询雇员姓名以s结尾的员工信息

select * from emp where ename like '%s';--匹配S结尾的雇员名字

3.查询雇员编号包含s的员工信息

select * from emp where ename like '%s%';--匹配雇员名字中包含S

4.查询第二个字母为A的员工与信息

select * from emp where like '_A%';--匹配第二个字母为A的雇员姓名

5.查询职位以"SALES_"开头的员工信息

select * from emp where job like 'SALES@_' escape '@';--模糊查询特殊字符时,使用escape语句做特殊处理;

select* from emp where job like 'SALES\_%' escape '\';

--is null 运算符

1.查询奖金为null的员工信息

select * from emp where comm=null;--not ok null值与任何值做计算都返回null

select * from emp where comm is null;--ok

--逻辑运算符

逻辑与(and): and :要求两个条件都为真,结果才为真

1.查询薪资大于1100,并且职位为CLERK的员工信息
select * from emp where sal>1100 and job ='CLERK';

--逻辑或(OR): OR: 两个条件中任意条件满足,结果即为真
1.查询薪资大于1100,或者职位为CLERK的员工信息
select * from emp where sal>1100 or job ='CLERK';

--逻辑非(NOT):对当前值取相反的值  
--     NOT运算符还可以和BETWEEN…AND、LIKE、IS NULL、IN一起使用
--between...and...
1.查询薪资不在2500到3000之间的员工信息
select * from emp where sal not between 2500 and 3000;

--like
1.查询雇员姓名不是以"S"开头的员工信息
select * from emp where ename not like 'S%';

--is null
1.查询奖金不为空的员工信息
select * from emp where comm is not null;

--in
1.查询不是10或者20部门的员工信息
select * from emp where deptno not in(10,20);

--运算符优先级  not > and > or
select * from emp where job= 'CLERK' or job='SALESMAN' and deptno=30;--7条数据
select * from emp where job= 'CLERK' or (job='SALESMAN' and deptno=30);--7条数据

select * from emp where (job= 'CLERK' or job='SALESMAN') and deptno=30; --4条数据

--order by 子句:默认升序 ,asc 升序 desc降序

--根据日期排序:日期早的比较小

select * from emp order by hiredate;     --默认升序

select * from emp order by hiredate asc;--升序

select * from emp order by hiredate desc;--降序

--根据数值排序: 按数值大小进行排序

select * from emp order by sal;   --默认升序

select * from emp order by sal asc;--升序

select * from emp order by sal desc; --降序

--根据字母排序:  按26个字母顺序自然排序

select * from emp order by ename;  --默认升序

select * from emp order by ename asc;--升序

select * from emp order by ename desc;--降序

--null值排序

select * from emp order by comm;--升序排序,null值排在最后

select * from emp order by comm desc;--降序排序,null值排在最前

--按列别名排序

select ename,sal,sal*12 yearsal from emp order by yearsal;

--多列参与排序
select empno,ename,deptno,job from emp order by deptno,job;     --根据deptno,job升序排序
select empno,ename,deptno,job from emp order by deptno,job asc; --根据deptno,job升序排序

select empno,ename,deptno,job from emp order by deptno,job desc;    --deptno升序、job降序
select empno,ename,deptno,job from emp order by deptno asc,job desc;--deptno升序、job降序

select empno,ename,deptno,job from emp order by deptno desc,job desc;--deptno降序、job降序

--按结果集列序号排序
select * from emp order by 1;--根据第一列升序排序
select * from emp order by 2;--根据第二列升序排序
select * from emp order by 9;--not ok  总列数为8,取值范围1-8之间
select empno,ename,job from emp order by 3;--总列数为3,取值范围1-3之间
 

 

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

_努力赚钱

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值