Oracle-4 限制数据和对数据排序


使用where子句: 数值型、字符型、日期型

比较数值型数据
查询所有不在部门10的员工信息
select * from emp where deptno<>10;

比较字符型数据
查询职位为’CLERK’的所有员工的信息
select * from emp where job = ‘CLERK’;

比较日期型
1.查询所以在1981年之后入职的员工信息(1981-12-31)
select * from emp where hiredate > ‘31-12月-81’;


特殊比较运算符 between…and…,in,like,is null

使用between .. and.. 运算符来判断要比较的值是否在某个范围内
查询薪水在1100到2000之间的所有员工信息
select * from emp where sal between 1100 and 2000;

IN运算符 : 判断要比较的值是否和集合列表中的任何一个值相等
查询部门编号为10 或者 20 的所有员工信息
select * from emp where deptno in(10,20);

like运算符 %代表任意个数的字符 _代表任意一个字符
查询所有名字包含’S’字母的员工信息
select * from emp where ename like ‘%S%’;

查询所有名字中第二个字母为’A’的员工信息
select * from emp where ename like ‘_A%’;

查询所有职位中以’SALE_’开头的员工信息
select * from emp where job like ‘SALE@_%’ escape ‘@’;
使用’@’符号与’escape’做特殊符号的查询

is null运算符 判断是否为空值(注意:不是空格” 不是0)
查询所有没有奖金的员工信息
select * from emp where comm is null;


逻辑运算符: and or not

逻辑与(and):所有判断条件必须都满足
查询薪水大于1100,并且职位为CLERK的员工姓名、编号、薪水、职位信息
select ename,empno,sal,job from emp where sal>1100 and job=’CLERK’;

逻辑或(or):只要任意条件满足,就算匹配
查询薪水大于1100,或职位为CLERK的员工姓名、编号、薪水、职位信息
select ename,empno,sal,job from emp where sal > 1100 or job=’CLERK’;

逻辑非(not):取相反的结果,NOT运算符还可以和BETWEEN…AND、LIKE、IS NULL一起使用
not in
查询部门编号不在 10 或者 20 的所有员工信息
select * from emp where deptno not in(10,20);

not between ..and..
查询薪水不在1100到2000范围以内的员工信息
select * from emp where sal not between 1100 and 2000;

not like
查询职位信息中不包含’SALES’的员工信息
select * from emp where job not like ‘%SALES%’;

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

运算符优先级: not > and > or
查询薪水大于1100并且薪水小于2000,或职位为CLERK的员工姓名、编号、薪水、职位信息
select * from emp where (sal >1100 and sal <2000) or job =’CLERK’;

查询薪水大于1100,并且薪水小于2000,或职位为CLERK的员工姓名、编号、薪水、职位信息
select * from emp where sal >1100 and sal <2000 or job =’CLERK’;
select * from emp where job =’CLERK’ or (sal >1100 and sal <2000);

查询职位为CLERK或者职位为SALE SMAN,并且部门编号为30的员工信息
select * from emp where (job =’CLERK’ or job=’SALESMAN’) and deptno=30;–正确


order by 子句:排序 asc升序(可省略) desc降序

按列名排序:日期类型
select * from emp order by hiredate; – 默认升序排序,asc可省略
select * from emp order by hiredate asc;
select * from emp order by hiredate desc;–降序排序

按列名排序:数值类型
select * from emp order by sal asc;
select * from emp order by sal desc;–降序排序

按列名排序:字符类型
select * from emp order by ename asc;
select * from emp order by ename desc;–降序排序

按列别名排序
select empno,ename,hiredate,sal,(sal*12) totalSal from emp order by totalSal;

多列参与排序,每列之间”,”逗号隔开
查询员工信息,并且根据部门、薪水升序排序
select * from emp order by deptno,sal asc;–deptno与sal均升序排序

按结果集列序号排序
select * from emp order by 2;–根据结果集第二列排序
select * from emp order by 3,2;–根据结果集第三列、第二列进行排序

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值