OCP-1Z0-051-題目解析-第11題

來源:互聯網
上載者:User

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 atax 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.7875CPU D300                          272.9625CPU D400                          310.6375CPU D600                           404.825GP 1024x768                        233.575GP 1280x1024                       267.825GP 800x600                           182.2MB - S300                         194.1875MB - 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.7875CPU D300                          272.9625CPU D400                          310.6375CPU D600                           404.825GP 1024x768                        233.575GP 1280x1024                       267.825GP 800x600                           182.2MB - S300                         194.1875MB - 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了,顯示和題目說的不一致。


相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.