OCP試題疑問集-051

131. View the Exhibitand examine the structure of the PRODUCT, COMPONENT, and PDT_COMP

tables.

In PRODUCT table, PDTNOis the primary key.

In COMPONENT table,COMPNO is the primary key.

In PDT_COMP table,(PDTNO,COMPNO) is the primary key, PDTNO is the foreign key referencing

PDTNO in PRODUCT tableand COMPNO is the foreign key referencing the COMPNO in COMPONENT

table.

You want to generate areport listing the product names and their corresponding component names, ifthe

component names andproduct names exist.

Evaluate the followingquery:

SQL>SELECTpdtno,pdtname, compno,compname

FROM product _____________pdt_comp

USING (pdtno)____________ component USING(compno)

WHERE compname IS NOTNULL;

Which combination ofjoins used in the blanks in the above query gives the correct output?

A. JOIN; JOIN

B. FULL OUTER JOIN; FULLOUTER JOIN

C. RIGHT OUTER JOIN; LEFTOUTER JOIN

D. LEFT OUTER JOIN;RIGHT OUTER JOIN

Answer: C


這道題乍一看,確實很繞。

if the component names and product names exist.要找到組件名和產品名都不爲空的數據,其實包含了四個條件。

1.product表中的product name不爲空

2.componet表中的component name不爲空

3.product表中的數據必須在pdt_comp表中出現,否則不管用哪種外連接,都會導致某一個name爲空

4.componet表中的數據必須在pdt_comp表中出現,否則不管用哪種外連接,都會導致某一個name爲空

由於有WHERE compname IS NOTNULL;所以不論連接方式如何.條件2必定滿足。

也就是說,只需考慮條件1,3,4滿足情況。

A選項用兩個內連接,是最容易分析。因爲pdt_comp表的主鍵是以外鍵形式參照另兩張表的,所以兩次內連接後

可以看成以pdt_comp爲驅動表連接其他兩張表。這樣3.4條件就符合了。

唯獨條件1無法滿足。

B選項用兩個全外連接。因爲pdt_comp表的主鍵是以外鍵形式參照另兩張表的,意味着先以product表作驅動表左連接pdt_comp。

這將導致出現product表中存在,而pdt_comp中不存在數據會被顯示出來。當然由於最後WHERE compname IS NOTNULL的條件,

這些數據又被過濾掉,因此條件3被滿足。之後又以componet表作爲驅動表左連接pdt_comp,這將導致出現componet表中存在,

而pdt_comp中不存在數據會被顯示出來。這將導致條件4不被滿足。同時條件1也無法滿足。

D選項和B選項是一樣。就不多說了

C選項先右在左連接。意味着以pdt_comp爲驅動表左連接其他兩張表。和A選項是一樣的。

同樣無法滿足條件1,所以我認爲也不是正確答案。


141. View the Exhibitand examine the structure of CUSTOMERS and GRADES tables.

You need to displaynames and grades of customers who have the highest credit limit.

Which two SQL statementswould accomplish the task? (Choose two.)

A. SELECT custname,grade

FROM customers, grades

WHERE (SELECTMAX(cust_credit_limit)

FROM customers) BETWEENstartval and endval;

B. SELECT custname,grade

FROM customers, grades

WHERE (SELECT MAX(cust_credit_limit)

FROM customers)

A. SELECT custname,grade

FROM customers, grades

WHERE (SELECTMAX(cust_credit_limit)

FROM customers) BETWEENstartval and endval;

B. SELECT custname,grade

FROM customers, grades

WHERE (SELECTMAX(cust_credit_limit)

FROM customers) BETWEEN startval and endval

AND cust_credit_limit BETWEEN startval AND endval;

C. SELECT custname,grade

FROM customers, grades

WHERE cust_credit_limit= (SELECT MAX(cust_credit_limit)

FROM customers)

AND cust_credit_limitBETWEEN startval AND endval;

D. SELECT custname,grade

FROM customers , grades

WHERE cust_credit_limitIN (SELECT MAX(cust_credit_limit)

FROM customers)

ANDMAX(cust_credit_limit) BETWEEN startval AND endval;

Answer: BC

疑問在B選項,第一個條件(SELECTMAX(cust_credit_limit) FROM customers) BETWEEN startval and endval

確定最大值所在的級別,但第二個條件cust_credit_limit BETWEEN startval AND endval;會把比最大值小,但

同屬一個級別的顧客檢索出來。

D選項的問題出在,後一個條件裏的分組函數不應出現(此處應該用子查詢)。導致ORA錯誤。

146. Evaluate thefollowing SQL statement:

SQL> SELECT cust_id,cust_last_name

FROM customers

WHERE cust_credit_limitIN

(selectcust_credit_limit

FROM customers

WHERE cust_city='Singapore');

Which statement is trueregarding the above query if one of the values generated by the subquery is

NULL?

A. It produces an error.

B. It executes butreturns no rows.

C. It generates outputfor NULL as well as the other values produced by the subquery.

D. It ignores the NULLvalue and generates output for the other values produced by the subquery.

Answer: C

經實測,子查詢爲NULL的行會被無視掉。這題的答案應該爲D


149. View the Exhibitsand examine the structures of the COSTS and PROMOTIONS tables.

Evaluate the followingSQL statement:

SQL> SELECT prod_idFROM costs

WHERE promo_id IN(SELECT promo_id FROM promotions

WHERE promo_cost <ALL

(SELECT MAX(promo_cost)FROM promotions

GROUP BY(promo_end_datepromo_

begin_date)));

What would be theoutcome of the above SQL statement?

A. It displays prod IDsin the promo with the lowest cost.

B. It displays prod IDsin the promos with the lowest cost in the same time interval.

C. It displays prod IDsin the promos with the highest cost in the same time interval.

D. It displays prod IDsin the promos with cost less than the highest cost in the same time interval.

Answer: D

可能是我的英文不好,我覺得D選項應該寫成 It displays prod IDsin the promos with cost less than all the highest cost in the each time interval.

150. View the Exhibitand examine the data in the PROMOTIONS table.

You need to display allpromo categories that do not have 'discount' in their subcategory.

Which two SQL statementsgive the required result? (Choose two.)


A. SELECTpromo_category

FROMpromotions

MINUS

SELECTpromo_category

FROMpromotions

WHEREpromo_subcategory = 'discount';

B. SELECTpromo_category

FROMpromotions

INTERSECT

SELECTpromo_category

FROMpromotions

WHEREpromo_subcategory = 'discount';

C. SELECTpromo_category

FROMpromotions

MINUS

SELECTpromo_category

FROMpromotions

WHEREpromo_subcategory <> 'discount';

D. SELECTpromo_category

FROMpromotions

INTERSECT

SELECTpromo_category

FROMpromotions

WHEREpromo_subcategory <> 'discount';

Answer: AD

D選項有問題,如果某個分類的子分類即包含 'discount'也包含非 'discount'數據,會被選出來。


169. View the Exhibitand examine the description for the PRODUCTS and SALES table.

PROD_ID is a primary keyin the PRODUCTS table and foreign key in the SALES table. You want to

remove all the rows fromthe PRODUCTS table for which no sale was done for the last three years.

Which is the validDELETE statement?

A. DELETE

FROM products

WHERE prod_id = (SELECTprod_id

FROM sales

WHERE time_id - 3*365 =SYSDATE );

B. DELETE

FROM products

WHERE prod_id = (SELECTprod_id

FROM sales

WHERE SYSDATE >=time_id - 3*365 );

C. DELETE

FROM products

WHERE prod_id IN (SELECTprod_id

FROM sales

WHERE SYSDATE - 3*365>= time_id);

D. DELETE

FROM products

WHERE prod_id IN (SELECTprod_id

FROM sales

WHERE time_id >=SYSDATE - 3*365 );

Answer: C

remove all the rows from the PRODUCTS table for which no sale was done for the last three years.要求是刪除過去3年裏沒有發生交易的商品ID。

首先PROD_ID is a primary keyin the PRODUCTS table and foreign key in the SALES table,即使過去3年裏沒有發生交易,3年之前仍然可能存在交易,因此由於存在外鍵關聯,products表的記錄是不能被刪除的。

而且C選項的子查詢檢索的是3年之前的交易記錄。和3年之內的交易沒有任何關係。所以爲什麼選C完全看不懂。



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章