zoukankan      html  css  js  c++  java
  • OCP-1Z0-051-题目解析-第11题

    11. View the Exhibit and examine the structure of the PRODUCTS table.
    All products have a list price. 
    You issue the following command to display the total price of each product after a discount of 25% and a
    tax of 15% are  applied on it. Freight charges of $100 have to be applied to all the products.
    SQL>SELECT prod_name, prod_list_price -(prod_list_price*(25/100))                 
    +(prod_list_price -(prod_list_price*(25/100))*(15/100))+100                                 
    AS "TOTAL PRICE" 
    FROM products; 

    What would be the outcome if all the parentheses are removed from the above statement?
     
    A. It produces a syntax error.
    B. The result remains unchanged. 
    C. The total price value would be lower than the correct value. 
    D. The total price value would be higher than the correct value.
     
    Answer: B
    题目解析:
    题目的意思是:表中产品的价格降价25%后,加上税金15%,再加上运费100后产品的新价格。题目给出了产品新价格的sql语句,
    问,假设把该sql语句的括号都去了,结果会如何?
    这题也是考表达式的运算顺序
    原sql运行结果
    复制代码
    SELECT prod_name, prod_list_price -(prod_list_price*(25/100))                    
       +(prod_list_price -(prod_list_price*(25/100))*(15/100))+100                                    
      AS "TOTAL PRICE"   
      FROM products where rownum<10;   
      
    PROD_NAME                         TOTAL PRICE  
    --------------------------------- -----------  
    VRAM - 64 MB                      577.7875
    CPU D300                          272.9625
    CPU D400                          310.6375
    CPU D600                           404.825
    GP 1024x768                        233.575
    GP 1280x1024                       267.825
    GP 800x600                           182.2
    MB - S300                         194.1875
    MB - S450                          213.025
    复制代码

    去括号后sql运行结果

    复制代码
    SELECT prod_name, prod_list_price -prod_list_price*25/100                    
       +prod_list_price -prod_list_price*25/100*15/100+100                                    
      AS "TOTAL PRICE"   
      FROM products where rownum<10;   
      
    PROD_NAME                         TOTAL PRICE  
    --------------------------------- -----------  
    VRAM - 64 MB                      577.7875
    CPU D300                          272.9625
    CPU D400                          310.6375
    CPU D600                           404.825
    GP 1024x768                        233.575
    GP 1280x1024                       267.825
    GP 800x600                           182.2
    MB - S300                         194.1875
    MB - S450                          213.025
    复制代码

    结果是一样的,所以选B

    事实上这道题,题目给的sql的括号位置应该错了,正确的应该是 这种

     SELECT prod_name, prod_list_price -(prod_list_price*(25/100)) 
    +(prod_list_price -(prod_list_price*(25/100)))*(15/100)+100 
    AS "TOTAL PRICE" 
    FROM products;

    假设是题目给的括号位置,能够測试下

    select 100 -(100*(25/100))+(100 -(100*(25/100))*(15/100))+100  from dual;

     

    100-(100*(25/100))+(100-(100*(25/100))*(15/100))+100
    ----------------------------------------------------
    271.25

    结果是271.25了,显示和题目说的不一致。


  • 相关阅读:
    Objective-C NSFileManager 文件管理总结
    ScrollView在RelativeLayout失效问题
    解决myeclipse中struts2 bug问题包的替换问题
    SOA究竟是个啥
    Flash--元件和实例
    MyEclipse中加入web项目到tomcat
    [C]if (CONDITION)语句中CONDITION的情况
    GTK经常使用控件之笔记本控件( GtkNotebook )
    org.apache.solr.handler.dataimport.DataImportHandlerException: Data Config problem: 对实体 &quot;characterEn
    Android自动测试之Monkey工具
  • 原文地址:https://www.cnblogs.com/tlnshuju/p/7098504.html
Copyright © 2011-2022 走看看