天天看點

OCP-1Z0-051 第149題 子查詢中ALL的應用

一、原題

View the Exhibits and examine the structures of the COSTS and PROMOTIONS tables.

OCP-1Z0-051 第149題 子查詢中ALL的應用

Evaluate the following SQL statement:

SQL>SELECT prod_id

      FROM costs

     WHERE promo_id IN

           (SELECT promo_id

              FROM promotions

             WHERE promo_cost < ALL

             (SELECT MAX(promo_cost)

                      FROM promotions

                     GROUP BY (promo_end_date - promo_begin_date)));

What would be the outcome of the above SQL statement?

A. It displays prod IDs in the promo with the lowest cost.

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

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

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

答案:D

二、題目翻譯

檢視COSTS and PROMOTIONS表的結構.

評估下面的SQL語句

上面SQL的執行結果什麼?

A.顯示promo最低的prod IDs。

B.顯示相同時間段内promo最低的prod IDs。

C.顯示相同時間段内promo最高的prod IDs。

D.顯示相同時間段内promo的cost小于最高的cost的prod IDs。

三、題目解析

子查詢

SELECT MAX(promo_cost)

  FROM promotions

 GROUP BY (promo_end_date - promo_begin_date)

求出來的,是每個促銷活動期間内的最大的成本。

然後 promo_cost < ALL(.. ),表示小于 剛子查詢查出來的所有這些最大成本結果集中,最小的那個。

然後,再根據活動ID,查出産品ID。

D選項中,描述也不是太準确,但是在幾個選項的描述中,D是最接近的。

繼續閱讀