yui 发表于 2013-3-3 21:06:41

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

个人的理解, 内联视图通常是指: 一个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?


懂ni 发表于 2013-3-13 18:20:53

支持一下:lol

qazxsw1 发表于 2013-5-15 18:41:38

生,容易。活,容易。生活,不容易。

sdtf08 发表于 2013-5-15 22:56:10

如果没有毛片,中国的性教育简直就是一片空白!

1397535668 发表于 2013-5-16 00:56:18

我喜欢孩子,更喜欢造孩子的过程!

zjxhx 发表于 2013-5-16 04:48:44

男人有冲动可能是爱你,也可能是不爱,但没有冲动肯定是不爱!

纸水仙 发表于 2013-5-16 08:34:08

天塌下来你顶着,我垫着!
页: [1]
查看完整版本: OCP考题解析_007: 内联视图优化all或any操作符