• OCP-1Z0-051-V9.02-101题


    101. Examine the data in the PROMO_BEGIN_DATE column of the PROMOTIONS table:

    PROMO_BEGIN _DATE

    04-jan-00

    10-jan-00

    15-dec-99

    18-oct-98

    22-aug-99

    You want to display the number of promotions started in 1999 and 2000.

    Which query gives the correct output?

    A. SELECT SUM(DECODE(SUBSTR(promo_begin_date,8),'00',1,0)) "2000",

    SUM(DECODE(SUBSTR(promo_begin_date,8),'99',1,0)) "1999"

    FROM promotions;

    B. SELECT SUM(CASE TO_CHAR(promo_begin_date,'yyyy') WHEN '99' THEN 1

    ELSE 0 END) "1999",SUM(CASE TO_CHAR(promo_begin_date,'yyyy') WHEN '00' THEN 1

    ELSE 0 END) "2000"

    FROM promotions;

    C. SELECT COUNT(CASE TO_CHAR(promo_begin_date,'yyyy') WHEN '99' THEN 1

    ELSE 0 END) "1999",COUNT(CASE TO_CHAR(promo_begin_date,'yyyy') WHEN '00' THEN 1

    ELSE 0 END) "2000"

    FROM promotions;

    D. SELECT COUNT(DECODE(SUBSTR(TO_CHAR(promo_begin_date,'yyyy'), 8), '1999', 1, 0)) "1999",

    COUNT(DECODE(SUBSTR(TO_CHAR(promo_begin_date,'yyyy'), 8),'2000', 1,

    0)) "2000"

    FROM promotions;

    Answer: A

    答案解析:

    分析A答案

    SUBSTR(promo_begin_date,8),即是取日期的最后两个值。

    (DECODE(SUBSTR(promo_begin_date,8),'00',1,0)如果最后两个值是00,则值为1,否则为0 

    (DECODE(SUBSTR(promo_begin_date,8),'99',1,0)如果最后两个值是99,则值为1,否则为0 

     SUM(DECODE(SUBSTR(promo_begin_date,8),'00',1,0)) 加起来有多少个1,即有多少个2000年的

    SUM(DECODE(SUBSTR(promo_begin_date,8),'99',1,0))加起来有多少个1,即有多少个1999年的

    B,条件不对,应该 TO_CHAR(promo_begin_date,'yyyy') 改成 TO_CHAR(promo_begin_date,'yy') 

    C,与B同样错误

    D,截取不对,SUBSTR(TO_CHAR(promo_begin_date,'yyyy'), 8)改成SUBSTR(TO_CHAR(promo_begin_date,'yyyy'), 1)

  • 相关阅读:
    单链表反转
    【华为悦读汇】技术发烧友:M-LAG
    Linux系列—策略路由、ip rule、ip route
    对象存储,为什么那么火?
    关于存储技术的最强入门科普
    OpenStack入门科普,看这一篇就够啦!
    虚拟化技术的本质
    师屎胜于熊便:FCoE iSCSI FC组网PK
    懂了!VMware/KVM/Docker原来是这么回事儿
    集群文件系统是什么
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13316876.html
Copyright © 2020-2023  润新知