sql语句注意的事项

(1)执行“select sal from scott.emp where ename=‘WARD’” ,得出 sal=1250;

(2)执行“select  emp.empno,emp.ename,emp.job,emp.sal  from scott.emp where

sal>=1250;”

4.4.2   带【in】的嵌套查询

select  emp.empno,emp.ename,emp.job,emp.sal

from scott.emp

where sal in (select sal from scott.emp where ename=‘WARD’);

上述语句完成的是查询薪水和 WARD相等的员工,也可以使用【not in】来进行查询。

4.4.3   带【any】的嵌套查询

select  emp.empno,emp.ename,emp.job,emp.sal

from scott.emp

where sal >any(select sal from scott.emp where job=‘MANAGER’);

带 any的查询过程等价于两步的执行过程。

(1)执行“select sal from scott.emp where job=‘MANAGER’”,其结果如图 4.22 所示。

(2)查询到 3 个薪水值 2975、2850 和 2450,父查询执行下列语句。

select  emp.empno,emp.ename,emp.job,emp.sal

from scott.emp

where sal >2975 or sal>2850 or sal>2450;

4.4.4   带【some】的嵌套查询

select  emp.empno,emp.ename,emp.job,emp.sal

from scott.emp

where sal =some(select sal from scott.emp where job=‘MANAGER’);

带 some 的嵌套查询与 any的步骤相同。

(1)子查询,执行“select  sal from scott.emp where job=‘MANAGER’”,其结果如图 4.22

所示。

(2)父查询执行下列语句。

select  emp.empno,emp.ename,emp.job,emp.sal

from scott.emp

where sal =2975 or sal=2850 or sal=2450;

带【any】的嵌套查询和【some】的嵌套查询功能是一样的。早期的 SQL 仅仅允

许使用【any】 ,后来的版本为了和英语的【any】相区分,引入了【some】 ,同时还保留了【any】

关键词。

4.4.5   带【all】的嵌套查询

select  emp.empno,emp.ename,emp.job,emp.sal

from scott.emp

where sal >all(select sal from scott.emp where job=‘MANAGER’);

带 all 的嵌套查询与【some】的步骤相同。

(1)子查询,结果如图 4.22 所示。

(2)父查询执行下列语句。

select  emp.empno,emp.ename,emp.job,emp.sal

from scott.emp

where sal >2975 and sal>2850 and sal>2450;

4.4.6   带【exists】的嵌套查询

select  emp.empno,emp.ename,emp.job,emp.sal

from scott.emp,scott.dept

where exists

(select * from scott.emp where scott.emp.deptno=scott.dept.deptno);

4.4.7   并操作的嵌套查询

并操作就是集合中并集的概念。属于集合 A或集合 B 的元素总和就是并集。

(select deptno from scott.emp)

union

(select deptno from scott.dept);

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

4.4.8   交操作的嵌套查询

交操作就是集合中交集的概念。属于集合 A且属于集合 B 的元素总和就是交集。

(select deptno from scott.emp)

intersect

(select deptno from scott.dept);

单击【执行】按钮,出现如图 4.27 所示的结果。

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

4.4.9   差操作的嵌套查询

差操作就是集合中差集的概念。属于集合 A且不属于集合 B 的元素总和就是差集。

(select deptno from scott.dept)

minus

(select deptno from scott.emp);

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

并、交和差操作的嵌套查询要求属性具有相同的定义,包括类型和取值范围
子查询除非能确保内层select只返回一个行的值,否则应在外层where子句中用

最后

小编这些年深知大多数初中级Android工程师,想要提升自己,往往是自己摸索成长,自己不成体系的自学效果低效漫长且无助

因此我收集整理了一份《2024年Android移动开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友。

由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、电子书籍、讲解视频,并且后续会持续更新

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人

都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

如果你需要这些资料, ⬅ 专栏获取
img-3rMuCrqR-1719254422552)]

由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、电子书籍、讲解视频,并且后续会持续更新

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人

都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

如果你需要这些资料, ⬅ 专栏获取

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值