clickhouse算术函数

--求和
SELECT plus(12, 21), plus(10, -10), plus(-10, -10);
+------------+-------------+--------------+
|plus(12, 21)|plus(10, -10)|plus(-10, -10)|
+------------+-------------+--------------+
|33          |0            |-20           |
+------------+-------------+--------------+

--差值
SELECT minus(10, 5), minus(10, -10), minus(-10, -10);
+------------+--------------+---------------+
|minus(10, 5)|minus(10, -10)|minus(-10, -10)|
+------------+--------------+---------------+
|5           |20            |0              |
+------------+--------------+---------------+

--积
SELECT multiply(12, 2), multiply(12, -2), multiply(-12, -2);
+---------------+----------------+-----------------+
|multiply(12, 2)|multiply(12, -2)|multiply(-12, -2)|
+---------------+----------------+-----------------+
|24             |-24             |24               |
+---------------+----------------+-----------------+

--平均值
SELECT divide(12, 4), divide(10, 3), divide(2, 4), divide(-4, -2), divide(-4, 2), divide(-4.5, 3);
+-------------+------------------+------------+--------------+-------------+---------------+
|divide(12, 4)|divide(10, 3)     |divide(2, 4)|divide(-4, -2)|divide(-4, 2)|divide(-4.5, 3)|
+-------------+------------------+------------+--------------+-------------+---------------+
|3            |3.3333333333333335|0.5         |2             |-2           |-1.5           |
+-------------+------------------+------------+--------------+-------------+---------------+

SELECT intDiv(10, 3), divide(10, 3); 
+-------------+------------------+
|intDiv(10, 3)|divide(10, 3)     |
+-------------+------------------+
|3            |3.3333333333333335|
+-------------+------------------+

SELECT divide(10, 0), divide(-10, 0); -- 出现无穷大字符“ ∞ ”或“ -∞ ”
+-------------+--------------+
|divide(10, 0)|divide(-10, 0)|
+-------------+--------------+
|∞            |-∞            |
+-------------+--------------+

SELECT divide(0, 0); -- 特殊字符(类似乱码)
+------------+
|divide(0, 0)|
+------------+
|NaN         |
+------------+

SELECT intDivOrZero(10, 0);
-- 0
+-------------------+
|intDivOrZero(10, 0)|
+-------------------+
|0                  |
+-------------------+

--求余数
SELECT modulo(10, 3); --1
+-------------+
|modulo(10, 3)|
+-------------+
|1            |
+-------------+

SELECT modulo(10.5, 3);
+---------------+
|modulo(10.5, 3)|
+---------------+
|1              |
+---------------+

--取反
SELECT negate(10), negate(-10);
+----------+-----------+
|negate(10)|negate(-10)|
+----------+-----------+
|-10       |10         |
+----------+-----------+

--绝对值
SELECT abs(-10), abs(10);
+--------+-------+
|abs(-10)|abs(10)|
+--------+-------+
|10      |10     |
+--------+-------+

--最大公约数
SELECT gcd(12, 24), gcd(-12, -24), gcd(-12, 24);
+-----------+-------------+------------+
|gcd(12, 24)|gcd(-12, -24)|gcd(-12, 24)|
+-----------+-------------+------------+
|12         |12           |12          |
+-----------+-------------+------------+

--最小公倍数
SELECT lcm(12, 24), lcm(-12, -24), lcm(-3, 4);
+-----------+-------------+----------+
|lcm(12, 24)|lcm(-12, -24)|lcm(-3, 4)|
+-----------+-------------+----------+
|24         |24           |12        |
+-----------+-------------+----------+

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值