ITPub博客

首页 > 数据库 > Oracle > OCP考题解析_007: 内联视图优化all或any操作符

OCP考题解析_007: 内联视图优化all或any操作符

原创 Oracle 作者:幕南风 时间:2014-07-03 13:48:38 0 删除 编辑
       个人的理解, 内联视图通常是指: 一个SQL查询的结果作为另一个查询的数据源, 一般在 From字句后面
       
       any表示数据集中的任何一个、相当于or
       x > any (select sal from emp where job=\'ANA\')
       等价于:
       exists (select sal from emp where job=\'ANA\' and x > sal)
       
       使用ALL和ANY的子查询总是可以用内嵌视图来代替,而且这个视图的性能要好的多,因为它利用了被连接表上的索引
       
       比如:any操作符
       

       需求:返回所有birthday > 出生于1985年之后的任何客户 的职员名称

select ename
from emp
where birthdate > any
        (select birthdate from customer where birthdate > \'31-DEC-1985\')


       上面的SQL语句可以优化为

select ename
from emp,(select min(birthdate) min_bday from customer where birthdate > \'31-DEC-1985\') in_line_view
where emp.birthdate > in_line_view.min_bday;


       OCP考题:

Q: 8 Click the Exhibit button and examine the data from the ORDERS and
CUSTOMERS tables.
Evaluate this SQL statement:

SELECT cust_id, ord_total
FROM orders
WHERE ord_total > ANY(SELECT ord_total
FROM orders
WHERE cust_id IN (SELECT cust_id
FROM customers
WHERE city LIKE
\'New York\'));

What is the result when the above query is executed?  


<!-- Baidu Button BEGIN -->

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/26515977/viewspace-1208009/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: OCP考题解析_042:控制文件的备份和转储
下一篇: 索引的小知识点:create index
请登录后发表评论 登录
全部评论
腾讯数据库工程师

注册时间:2012-05-10

最新文章