sql算术运算符_SQL中的算术运算符

sql算术运算符

SQL | 算术运算符 (SQL | Arithmetic Operators)

Different number-crunching administrators are utilized in SQL to be specific Addition (+), Subtraction (-), Multiplication (*), Division (/), Modulus (%).

SQL中使用了不同的数字运算管理员来表示特定的加法(+),减法(-),乘法(*),除法(/),模数(%)

For the further examples we will be referring to the following base table:

对于其他示例,我们将参考以下基础表:

Table: BOOKS

表:书

BookNoNameCostDiscount
9871Nancy Drew2005%
9560Goosebump25010%
9810Sherlock Holmes30015%
8700The Blue Umbrella2006%
5086Gulliver Travels1604%
1272Hellen Keller1504%
书号 名称 成本 折扣
9871 南希·德鲁 200 5%
9560 鸡皮ump 250 10%
9810 夏洛克·福尔摩斯 300 15%
8700 蓝伞 200 6%
5086 格列佛游记 160 4%
1272 海伦·凯勒 150 4%

1)加法(+) (1) Addition (+))

It is utilized to perform addition procedures on the information things, things incorporate either single section or different segments.

它用于对信息事物执行附加过程,这些事物包含单个部分或不同的段。

Implementation:

实现方式:

SELECT bookno, name, cost, discount, cost+50 AS "Final Cost" 
FROM BOOKS;

Output

输出量

BookNoNameCostDiscountFinal Cost
9871Nancy Drew2005%250
9560Goosebump25010%300
9810Sherlock Holmes30015%350
8700The Blue Umbrella2006%250
5086Gulliver Travels1604%210
1272Hellen Keller1504%200
书号 名称 成本 折扣 最终成本
9871 南希·德鲁 200 5% 250
9560 鸡皮ump 250 10% 300
9810 夏洛克·福尔摩斯 300 15% 350
8700 蓝伞 200 6% 250
5086 格列佛游记 160 4% 210
1272 海伦·凯勒 150 4% 200

Similarly, we can do the addition of two columns too.

同样,我们也可以添加两列。

2)减法(-) (2) Subtraction (-))

It is utilized to perform subtraction procedures on the information things, things incorporate either a single section or different segments.

它用于对信息事物执行减法过程,信息包含单个部分或不同的段。

Implementation:

实现方式:

SELECT bookno, name, cost, discount, cost-discount AS "Final Cost" 
FROM BOOKS;

Output

输出量

BookNoNameCostDiscountFinal Cost
9871Nancy Drew20012.50237.50
9560Goosebump25030.00270.00
9810Sherlock Holmes30052.50297.50
8700The Blue Umbrella20015.00235.00
5086Gulliver Travels1608.40201.6
1272Hellen Keller1508.00192.00
书号 名称 成本 折扣 最终成本
9871 南希·德鲁 200 12.50 237.50
9560 鸡皮ump 250 30.00 270.00
9810 夏洛克·福尔摩斯 300 52.50 297.50
8700 蓝伞 200 15.00 235.00
5086 格列佛游记 160 8.40 201.6
1272 海伦·凯勒 150 8.00 192.00

3)乘法(*) (3) Multiplication (*))

It is utilized to perform multiplication procedures on the information things, things incorporate either a single section or different segments.

它用于对信息事物执行乘法过程,这些事物包含单个节或不同段。

Implementation:

实现方式:

SELECT bookno, name, cost, discount, cost*discount AS "Final Cost" 
FROM BOOKS;

Output

输出量

BookNoNameCostDiscountFinal Cost
9871Nancy Drew20012.50‭2500‬
9560Goosebump25030.007500
9810Sherlock Holmes30052.5015750
8700The Blue Umbrella20015.003000
5086Gulliver Travels1608.401344
1272Hellen Keller1508.001200
书号 名称 成本 折扣 最终成本
9871 南希·德鲁 200 12.50 ‭2500‬
9560 鸡皮ump 250 30.00 7500
9810 夏洛克·福尔摩斯 300 52.50 15750
8700 蓝伞 200 15.00 3000
5086 格列佛游记 160 8.40 1344
1272 海伦·凯勒 150 8.00 1200

4)师(/) (4) Division (/))

It is utilized to perform division procedures on the information things, things incorporate either a single section or different segments.

它用于对信息事物执行划分过程,信息包含单个部分或不同的段。

Implementation:

实现方式:

SELECT bookno, name, cost, discount, cost/discount AS "Final Cost" 
FROM BOOKS;

Output

输出量

BookNoNameCostDiscountFinal Cost
9871Nancy Drew20012.50‭16.00‬
9560Goosebump25030.008.33
9810Sherlock Holmes30052.505.71
8700The Blue Umbrella20015.0013.33
5086Gulliver Travels1608.4019.04
1272Hellen Keller1508.0018.75
书号 名称 成本 折扣 最终成本
9871 南希·德鲁 200 12.50 ‭16.00‬
9560 鸡皮ump 250 30.00 8.33
9810 夏洛克·福尔摩斯 300 52.50 5.71
8700 蓝伞 200 15.00 13.33
5086 格列佛游记 160 8.40 19.04
1272 海伦·凯勒 150 8.00 18.75

5)模量(%) (5) Modulus (%))

This operator is used to get the remainder when the division operation is performed with the data.

当对数据执行除法运算时,该运算符用于获取余数。

Implementation:

实现方式:

SELECT bookno, name, cost, discount, cost%discount AS "Final Cost" 
FROM BOOKS;

Output

输出量

BookNoNameCostDiscountFinal Cost
9871Nancy Drew20012.50‭0‬
9560Goosebump25030.0010
9810Sherlock Holmes30052.5037.5
8700The Blue Umbrella20015.005
5086Gulliver Travels1608.400.4
1272Hellen Keller1508.006
书号 名称 成本 折扣 最终成本
9871 南希·德鲁 200 12.50 ‭0‬
9560 鸡皮ump 250 30.00 10
9810 夏洛克·福尔摩斯 300 52.50 37.5
8700 蓝伞 200 15.00 5
5086 格列佛游记 160 8.40 0.4
1272 海伦·凯勒 150 8.00 6

翻译自: https://www.includehelp.com/sql/arithmetic-operators.aspx

sql算术运算符

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值