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 wocould 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 wocould be lower than the correct value.
D. The total price value wocould be higher than the correct value.
Answer: B
Question Analysis:
The question is: after the price of the products in the table is reduced by 25%, the tax is increased by 15%, and the new price of the products after the freight is increased by 100. The question shows the SQL statement for the new product price,
Q: What will happen if I put all the parentheses in the SQL statement?
This is also the calculation order of the test expression.
Original SQL Execution result
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 Execution result after parentheses
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
The result is the same, so select B.
In fact, the question should be wrong in the brackets of the SQL statement.
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;
If the question is given with brackets, you can test
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
The result is 271.25, which is different from the question.