数学运算符符号 - AWS Clean Rooms

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

数学运算符符号

下表列出了支持的数学运算符。

支持的运算符

操作符 描述 示例 结果
+ 2 + 3 5
- 2 - 3 –1
* 2 * 3 6
/ 4 / 2 2
% 取模 5 % 4 1
^ 2.0 ^ 3.0 8
|/ 平方根 | / 25.0 5
||/ 立方根 || / 27.0 3
@ 绝对值 @ -5.0 5

示例

为给定交易计算支付的佣金加 2.00 美元手续费:

select commission, (commission + 2.00) as comm from sales where salesid=10000; commission | comm -----------+------- 28.05 | 30.05 (1 row)

为给定交易计算销售价格的 20%:

select pricepaid, (pricepaid * .20) as twentypct from sales where salesid=10000; pricepaid | twentypct ----------+----------- 187.00 | 37.400 (1 row)

根据持续增长模式预测票的销售量。在此示例中,子查询将返回 2008 年销售的票数。在此后 10 年,该结果将以 5% 的连续增长率呈指数增长。

select (select sum(qtysold) from sales, date where sales.dateid=date.dateid and year=2008) ^ ((5::float/100)*10) as qty10years; qty10years ------------------ 587.664019657491 (1 row)

查找带有大于或等于 2000 的日期 ID 的销售的总支付价格和总佣金。然后将总支付价格减去总佣金。

select sum (pricepaid) as sum_price, dateid, sum (commission) as sum_comm, (sum (pricepaid) - sum (commission)) as value from sales where dateid >= 2000 group by dateid order by dateid limit 10; sum_price | dateid | sum_comm | value -----------+--------+----------+----------- 364445.00 | 2044 | 54666.75 | 309778.25 349344.00 | 2112 | 52401.60 | 296942.40 343756.00 | 2124 | 51563.40 | 292192.60 378595.00 | 2116 | 56789.25 | 321805.75 328725.00 | 2080 | 49308.75 | 279416.25 349554.00 | 2028 | 52433.10 | 297120.90 249207.00 | 2164 | 37381.05 | 211825.95 285202.00 | 2064 | 42780.30 | 242421.70 320945.00 | 2012 | 48141.75 | 272803.25 321096.00 | 2016 | 48164.40 | 272931.60 (10 rows)