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

一、原题
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。
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值