您的位置:首页 > 其它

OCP-1Z0-051 第99题 AVG函数

2014-05-09 19:54 218 查看
一、原题

View the Exhibit and examine the structure of the PROMOTIONS table.



Using the PROMOTIONS table, you need to find out the average cost for all promos in the ranges $0-2000 and $2000-5000 in category A

You issue the following SQL statement:

SQL>SELECT AVG(CASE

             WHEN promo_cost BETWEEN 0 AND 2000 AND promo_category = 'A' then

              promo_cost

             ELSE

              null

           END) "CAT_2000A",

       AVG(CASE

             WHEN promo_cost BETWEEN 2001 AND 5000 AND promo_category = 'A' THEN

              promo_cost

             ELSE

              null

           END) "CAT_5000A"

  FROM promotions;

What would be the outcome?
A. It executes successfully and gives the required result.
B. It generates an error because NULL cannot be specified as a return value.

C. It generates an error because CASE cannot be used with group functions.

D. It generates an error because multiple conditions cannot be specified for the WHEN clause.

答案:A


二、题目翻译

下面是PROMOTIONS表的结构:

使用PROMOTIONS表,你需要找出category A中在$0-2000范围和$2000-5000范围内的所有promos的平均成本(cost).

执行下面的SQL语句:

结果是什么?

A.执行成功,并得出所需结果。

B.报错,因为NULL不能作为一个返回值被指定。

C.报错,因为CASE不能用在组函数中。

D.报错,因为WHEN子句不能指定多个条件。

三、题目解析

NULL值在avg函数中不会计算,所以计算平均值时会忽略null值,例如:返回4行,有1行为空,则平均值就是总数/3。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息