1Z0-051 QUESTION 11 运算顺序

本文通过一个具体的SQL查询示例,展示了如何计算产品在应用折扣和税费后的总价格,并探讨了去除括号后表达式的运算顺序对结果的影响。
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;

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


评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值