ny3259 发表于 2015-11-8 16:31:56

OCP-1Z0-051-V9.02-147题

  147. View the Exhibit and examine the structure of the PROMOTIONS table.
  Evaluate the following SQL statement:
  SQL>SELECT promo_name,CASE   
  WHEN promo_cost >=(SELECT AVG(promo_cost)      
  FROM promotions      
  WHERE promo_category='TV')         
  then 'HIGH'         
  else 'LOW'         
  END COST_REMARK
  FROM promotions;
  Which statement is true regarding the outcome of the above query?
  

  A. It shows COST_REMARK for all the promos in the table. 分类显示所有值
  B. It produces an error because the subquery gives an error.
  C. It shows COST_REMARK for all the promos in the promo category 'TV'.
  D. It produces an error because subqueries cannot be used with the CASE expression.
  Answer: A
  
  答案解析:
  1、首先运行子查询,得出一个数值
  
sh@TEST0910> SELECT AVG(promo_cost) FROM promotionsWHERE promo_category='TV';AVG(PROMO_COST)---------------   46260.8696  2、所有的promos 根据上面计算的数值,来进行分类。故选择A
sh@TEST0910> SELECT promo_name,CASE WHEN promo_cost >=2(SELECT AVG(promo_cost) FROM promotionsWHERE promo_category='TV')3then 'HIGH'else 'LOW'END COST_REMARK   4FROM promotions;PROMO_NAME                     COST------------------------------ ----NO PROMOTION #               LOWnewspaper promotion #16-108    LOWpost promotion #20-232         LOWnewspaper promotion #16-349    LOWinternet promotion #14-471   LOW  
         版权声明:本文为博主原创文章,未经博主允许不得转载。
页: [1]
查看完整版本: OCP-1Z0-051-V9.02-147题