1、Oracle sql语句(<>,any,some,all,is null,is not null,between * and *,in(list),not in(list),exits,like)

 

--!=不等于
select * from emp where deptno !=20;
--<>不等于
select * from emp where deptno <>20;
--any,取其中任意一个
select sal from emp where sal>any(1000,1500,3000);
--some,some跟any是同一个效果,只要大于其中某一个值都会成立
select sal from emp where sal>some(1000,1500,3000);
--all,大于所有的值才会成立
select sal from emp where sal>all(1000,1500,3000);
--is null为空
select * from emp where comm is null;
--is not null非空
select * from emp where comm is not null;
--between x and y,包含x和y的值
select * from emp where sal between 1500 and 3000;
--需要进行某些值的等值判断的时候可以使用in 和not in
--in(list),
select * from emp where deptno in(10,20);
--not in(list),
select * from emp where deptno not in(10,20);

--exits(sub-query)
--通过外层循环来规范内层循环
select *
  from emp e
 where exists(select deptno from dept d
 where (d.deptno = 10 or d.deptno = 20)
   and e.deptno = d.deptno)

--like
--查询名字以S开头的用户
--在like的语句中,需要使用占位符或者通配符
--_表示某个字符或者数字仅出现一次
--%表示任意字符出现任意次数
--以下查询名字以S开头的用户
select * from emp where ename like('S%')
--以下查询名字以S开头且倒数第二个字符为T的用户
select * from emp where ename like('S%T_');

练习题:
--查询部门编号为10的员工信息
select * from emp where deptno=20
--查询年薪大于3万的人员的姓名与部门编号
select empno,ename from emp where (sal * 12)>30000
--查询佣金为null的人员姓名与工资
select ename,sal from emp where comm is null
--查询工资大于1500且and含有佣金的人员姓名
select ename from emp where sal >1500 and comm is not null
--查询工资大于1500或or含用佣金的人员姓名
select ename from emp where sal>1500 or comm is not null
--查询姓名里面含有S员工信息 工资、名称
select ename,sal from emp where ename like('%S%')
--求姓名以J开头第二个字符O的员工姓名与工资
select ename,sal from emp where ename like('JO%')
--使用in查询部门名称为SALES和RESEARCH的雇员姓名、工资、部门编号
select e.ename, e.sal, e.deptno
  from emp e
 where e.deptno in (SELECT deptno
                      from dept d
                     where d.dname = 'SALES'
                        or d.dname = 'RESEARCH')

--order by进行排序操作
select * from emp order by sal;--默认情况为升序排序
select * from emp order by sal desc;--降序

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值