QUESTION 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;
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 parenthese s 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.
答案为B
解析如下:
因为去掉括号以后,运算顺序不影响结果,如下:
SQL> create table products(
2 prod_id number(6) not null,
3 prod_name varchar2(50) not null,
4 prod_desc varchar2(4000) not null,
5 prod_category varchar2(50) not null,
6 prod_category_id number not null,
7 prod_unit_of_measure varchar2(20),
8 supplier_id number(6) not null,
9 prod_status varchar2(20) not null,
10 prod_list_price number(8,2) not null,
11 prod_min_price number(8,2) not null);
表已创建。
SQL> insert into products values(100001,'test','test','testcategory','1','100000
1',100001,'10000',10000,800);
已创建 1 行。
SQL> SELECT prod_name, prod_list_price -(prod_list_price*(25/100))
2 +(prod_list_price -(prod_list_price*(25/100))*(15/100))+100
3 AS "TOTAL PRICE"
4 FROM products;
PROD_NAME TOTAL PRICE
-------------------------------------------------- -----------
test 17225
SQL> SELECT prod_name, prod_list_price -prod_list_price*25/100
2 +prod_list_price -prod_list_price*25/100*15/100+100
3 AS "TOTAL PRICE"
4 FROM products;
PROD_NAME TOTAL PRICE
-------------------------------------------------- -----------
test 17225
本文通过一个具体的SQL查询示例,展示了如何计算产品在应用折扣和税费后的总价格,并探讨了去除括号后表达式的运算顺序对结果的影响。
1828

被折叠的 条评论
为什么被折叠?



