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        |
+-----------+-------------+----------+

上一篇:quartus之LPM_DIVIDE


下一篇:矩阵连乘问题·动态规划