OCP 1Z0 051 145

145. View the Exhibit and examine the structure of the CUSTOMERS table. 
You issue the following SQL statement on the CUSTOMERS table to display the customers who are in the 
same country as customers with  the  last name  'KING'
and whose credit  limit  is  less  than  the maximum 
credit limit in countries that have customers with the last name 'KING':
 
SQL> SELECT cust_id,cust_last_name 
FROM customers 
WHERE country_id IN(SELECT country_id                      
FROM customers                      
WHERE cust_last_name ='King') 
AND cust_credit_limit < (SELECT MAX(cust_credit_limit)                          
FROM customers                          
WHERE country_id IN(SELECT country_id                                            
FROM customers                                            
WHERE cust_last_name='King')); 
Which statement is true regarding the outcome of the above query?  
OCP 1Z0 051 145_第1张图片
A. It executes and shows the required result. 
B. It produces an error and the < operator should be replaced by < ALL to get the required output. 
C. It produces an error and the < operator should be replaced by < ANY to get the required output. 
D. It produces an error and the   IN operator should be replaced by = in the WHERE clause of the main 
query to get the required output. 

A B C 因MAX() 只返回一条,所以在这儿“<”、 “< ALL” 、“< ANY” 都可以用
SQL> SELECT COUNT(*)
  2    FROM sh.customers
  3   WHERE country_id IN
  4         (SELECT country_id FROM customers WHERE cust_last_name = 'King')
  5     AND cust_credit_limit <
  6         (SELECT MAX(cust_credit_limit)
  7            FROM sh.customers
  8           WHERE country_id IN (SELECT country_id
  9                                  FROM sh.customers
 10                                 WHERE cust_last_name = 'King'));
  COUNT(*)
----------
        79
1 row selected

SQL> SELECT COUNT(*)
  2    FROM sh.customers
  3   WHERE country_id IN
  4         (SELECT country_id FROM customers WHERE cust_last_name = 'King')
  5     AND cust_credit_limit < ALL
  6         (SELECT MAX(cust_credit_limit)
  7            FROM sh.customers
  8           WHERE country_id IN (SELECT country_id
  9                                  FROM sh.customers
 10                                 WHERE cust_last_name = 'King'));
 
  COUNT(*)
----------
        79
1 row selected

SQL> SELECT COUNT(*)
  2    FROM sh.customers
  3   WHERE country_id IN
  4         (SELECT country_id FROM customers WHERE cust_last_name = 'King')
  5     AND cust_credit_limit < ANY
  6         (SELECT MAX(cust_credit_limit)
  7            FROM sh.customers
  8           WHERE country_id IN (SELECT country_id
  9                                  FROM sh.customers
 10                                 WHERE cust_last_name = 'King'));
 
  COUNT(*)
----------
        79
1 row selected



D 错误,cust_last_name ='King'返回多条而不是一条。

Answer: A 

你可能感兴趣的:(OCP 1Z0 051 145)