请教高手在sql里in,all,any,some的区别和具体应用范围

[复制链接]
查看11 | 回复0 | 2020-12-22 17:04:17 | 显示全部楼层 |阅读模式
给你些例子:in 是 确定集合的SELECT au_lname, stateFROM authorsWHERE state IN ('CA', 'IN', 'MD')结果:au_lname state-------- ----Yokomoto
CADeFrance
INStringer
CAMacFeather
CAKarsen
CAPanteley
MDHunter
CAall 是查询还可以是子查询如:select name from edit其中name前省略了all.name前可以加ALL|DISTINCTall是所有记录.distinct是不重复的。带【any】的嵌套查询和【some】的嵌套查询功能是一样的。早期的SQL仅仅允许使用【any】,后来的版本为了和英语的【any】相区分,引入了【some】,同时还保留了【any】关键词。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'” select emp.empno,emp.ename,emp.job,emp.sal from scott.emp where sal >2975 or sal>2850 or sal>2450; 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;
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行