Skip to content

Latest commit

 

History

History
22 lines (15 loc) · 704 Bytes

zhi-hang-suan-shu-ji-suan.md

File metadata and controls

22 lines (15 loc) · 704 Bytes

执行算数计算

计算字段的另一常见用途是对检索出的数据进行算术计算。举一个例子,orders表包含收到的所有订单,orderitems表包含每个订单中的各项物品。下面的SQL语句检索订单号20005中的所有物品:

SELECT prod_id, quantity, item_price
FROM orderitems
WHERE order_num = 20005;

item_price列包含订单中每项物品的单价。如下汇总物品的价格(单价乘以订购数量):

SELECT prod_id, quantity, item_price, quantity*item_price AS expanded_price
FROM orderitems
WHERE order_num = 20005;