PostgreSQL数值函数主要用于数值运算和/或数学计算。下表详细介绍了数字函数-
S. No. | Name & 描述 |
---|---|
1 |
ABS() 返回数值表达式的绝对值。 |
2 |
ACOS() 返回数值表达式的反余弦值,如果该值不在-1到1之间,则返回NULL。 |
3 |
ASIN() 返回数字表达式的反正弦值,如果值不在-1到1的范围内,则返回NULL |
4 |
ATAN() 返回数值表达式的反正切。 |
5 |
ATAN2() 返回传递给它的两个变量的反正切。 |
6 |
CEIL() 返回不小于传递的数字表达式的最小整数值 |
7 |
CEILING() 返回不小于传递的数字表达式的最小整数值 |
8 |
COS() 返回传递的数字表达式的余弦值。 |
9 |
COT() 返回传递的数值表达式的余切。 |
10 |
DEGREES() 返回从弧度转换为度的数值表达式。 |
11 |
EXP() 返回自然对数(e)的底数,该底数提高为传递的数值表达式的幂。 |
12 |
FLOOR() 返回不大于传递的数字表达式的最大整数值。 |
13 |
GREATEST() 返回输入表达式的最大值。 |
14 |
LEAST() 如果给定两个或多个,则返回最小值输入。 |
15 |
LOG() 返回所传递数值表达式的自然对数。 |
16 |
MOD() 通过潜水另一表达式来返回一个表达式的其余部分。 |
17 |
PI() 返回pi的值 |
18 |
POW() 返回一个表达式的值加到另一表达式的幂上 |
19 |
POWER() 返回一个表达式的值加到另一表达式的幂上 |
20 |
RADIANS() 返回传递的表达式的值,该表达式从度转换为弧度。 |
21 |
ROUND() 返回四舍五入为整数的数字表达式。 |
22 |
SIN() 返回以弧度为单位的数字表达式的正弦值。 |
23 |
SQRT() 返回数值表达式的非负平方根。 |
24 |
TAN() 返回以弧度表示的数字表达式的切线。 |
ABS(X)
ABS()函数返回X的绝对值。请考虑以下示例-
testdb=# SELECT ABS(2); +---------------------------------------------------------+ | ABS(2) | +---------------------------------------------------------+ | 2 | +---------------------------------------------------------+ 1 row in set (0.00 sec) testdb=# SELECT ABS(-2); +---------------------------------------------------------+ | ABS(2) | +---------------------------------------------------------+ | 2 | +---------------------------------------------------------+ 1 row in set (0.00 sec)
ACOS(X)
此函数返回X的反余弦。X的值必须在-1和1之间,否则将返回NULL。考虑以下示例-
testdb=# SELECT ACOS(1); +---------------------------------------------------------+ | ACOS(1) | +---------------------------------------------------------+ | 0.000000 | +---------------------------------------------------------+ 1 row in set (0.00 sec)
ASIN(X)
ASIN()函数返回X的反正弦值。X的值必须在-1到1的范围内,否则返回NULL。
testdb=# SELECT ASIN(1); +---------------------------------------------------------+ | ASIN(1) | +---------------------------------------------------------+ | 1.5707963267949 | +---------------------------------------------------------+ 1 row in set (0.00 sec)
ATAN(X)
此函数返回X的反正切。
testdb=# SELECT ATAN(1); +---------------------------------------------------------+ | ATAN(1) | +---------------------------------------------------------+ | 0.78539816339745 | +---------------------------------------------------------+ 1 row in set (0.00 sec)
ATAN2(Y,X)
此函数返回两个参数的反正切值:X和Y。它与Y/X的反正切相似,不同之处在于两者的符号均用于查找输出的象限。
testdb=# SELECT ATAN2(3,6); +---------------------------------------------------------+ | ATAN2(3,6) | +---------------------------------------------------------+ | 0.46364760900081 | +---------------------------------------------------------+ 1 row in set (0.00 sec)
CEIL(X)/CEILING(X)
这些函数返回不小于X的最小整数值。请考虑以下示例-
testdb=# SELECT CEILING(3.46); +---------------------------------------------------------+ | CEILING(3.46) | +---------------------------------------------------------+ | 4 | +---------------------------------------------------------+ 1 row in set (0.00 sec) testdb=# SELECT CEIL(-6.43); +---------------------------------------------------------+ | CEIL(-6.43) | +---------------------------------------------------------+ | -6 | +---------------------------------------------------------+ 1 row in set (0.00 sec)
COS(X)
此函数返回X的余弦。X的值以弧度给出。
testdb=#SELECT COS(90); +---------------------------------------------------------+ | COS(90) | +---------------------------------------------------------+ | -0.44807361612917 | +---------------------------------------------------------+ 1 row in set (0.00 sec)
COT(X)
此函数返回X的余切。请考虑以下示例-
testdb=#SELECT COT(1); +---------------------------------------------------------+ | COT(1) | +---------------------------------------------------------+ | 0.64209261593433 | +---------------------------------------------------------+ 1 row in set (0.00 sec)
DEGREES(X)
此函数返回从弧度转换为度的X值。
testdb=#SELECT DEGREES(PI()); +---------------------------------------------------------+ | DEGREES(PI()) | +---------------------------------------------------------+ | 180.000000 | +---------------------------------------------------------+ 1 row in set (0.00 sec)
EXP(X)
此函数返回e的值(自然对数的底数),升为X的幂。
testdb=#SELECT EXP(3); +---------------------------------------------------------+ | EXP(3) | +---------------------------------------------------------+ | 20.085537 | +---------------------------------------------------------+ 1 row in set (0.00 sec)
FLOOR(X)
此函数返回不大于X的最大整数值。
testdb=#SELECT FLOOR(7.55); +---------------------------------------------------------+ | FLOOR(7.55) | +---------------------------------------------------------+ | 7 | +---------------------------------------------------------+ 1 row in set (0.00 sec)
GREATEST(n1,n2,n3,.......)
GREATEST()函数返回一组输入参数(n1,n2,n3等)中的最大值。以下示例使用GREATEST()函数从一组数值中返回最大数-
testdb=#SELECT GREATEST(3,5,1,8,33,99,34,55,67,43); +---------------------------------------------------------+ | GREATEST(3,5,1,8,33,99,34,55,67,43) | +---------------------------------------------------------+ | 99 | +---------------------------------------------------------+ 1 row in set (0.00 sec)
LEAST(N1,N2,N3,N4,......)
LEAST()函数与GREATEST()函数相反。它的目的是从值列表中返回值最小的项(N1,N2,N3等)。以下示例显示LEAST()函数的正确用法和输出-
testdb=#SELECT LEAST(3,5,1,8,33,99,34,55,67,43); +---------------------------------------------------------+ | LEAST(3,5,1,8,33,99,34,55,67,43) | +---------------------------------------------------------+ | 1 | +---------------------------------------------------------+ 1 row in set (0.00 sec)
LOG(X)/LOG(B,X)
该函数的单参数版本将返回X的自然对数。如果使用两个参数调用它,则返回任意基数B的X的对数。请考虑以下示例-
testdb=#SELECT LOG(45); +---------------------------------------------------------+ | LOG(45) | +---------------------------------------------------------+ | 1.65321251377534 | +---------------------------------------------------------+ 1 row in set (0.00 sec) testdb=#SELECT LOG(2,65536); +---------------------------------------------------------+ | LOG(2,65536) | +---------------------------------------------------------+ | 16.000000 | +---------------------------------------------------------+ 1 row in set (0.00 sec)
MOD(N,M)
此函数返回N除以M的余数。请考虑以下示例-
testdb=#SELECT MOD(29,3); +---------------------------------------------------------+ | MOD(29,3) | +---------------------------------------------------------+ | 2 | +---------------------------------------------------------+ 1 row in set (0.00 sec)
PI()
该函数仅返回pi的值。 SQL在内部存储pi的完整双精度值。
testdb=#SELECT PI(); +---------------------------------------------------------+ | PI() | +---------------------------------------------------------+ | 3.141593 | +---------------------------------------------------------+ 1 row in set (0.00 sec)
POW(X,Y)/POWER(X,Y)
这两个函数将X的值返回到Y的幂。
testdb=# SELECT POWER(3,3); +---------------------------------------------------------+ | POWER(3,3) | +---------------------------------------------------------+ | 27 | +---------------------------------------------------------+ 1 row in set (0.00 sec)
RADIANS(X)
此函数返回X的值,将其从度转换为弧度。
testdb=#SELECT RADIANS(90); +---------------------------------------------------------+ | RADIANS(90) | +---------------------------------------------------------+ |1.570796 | +---------------------------------------------------------+ 1 row in set (0.00 sec)
ROUND(X)/ROUND(X,D)
此函数返回四舍五入到最接近的整数的X。如果提供了第二个参数D,则函数将X返回四舍五入到D的小数位。 D必须为正数,否则将删除小数点右边的所有数字。考虑以下示例-
testdb=#SELECT ROUND(5.693893); +---------------------------------------------------------+ | ROUND(5.693893) | +---------------------------------------------------------+ | 6 | +---------------------------------------------------------+ 1 row in set (0.00 sec) testdb=#SELECT ROUND(5.693893,2); +---------------------------------------------------------+ | ROUND(5.693893,2) | +---------------------------------------------------------+ | 5.69 | +---------------------------------------------------------+ 1 row in set (0.00 sec)
SIGN(X)
此函数返回X的符号(负,零或正)为-1、0或1。
testdb=#SELECT SIGN(-4.65); +---------------------------------------------------------+ | SIGN(-4.65) | +---------------------------------------------------------+ | -1 | +---------------------------------------------------------+ 1 row in set (0.00 sec) testdb=#SELECT SIGN(0); +---------------------------------------------------------+ | SIGN(0) | +---------------------------------------------------------+ | 0 | +---------------------------------------------------------+ 1 row in set (0.00 sec) testdb=#SELECT SIGN(4.65); +---------------------------------------------------------+ | SIGN(4.65) | +---------------------------------------------------------+ | 1 | +---------------------------------------------------------+ 1 row in set (0.00 sec)
SIN(X)
此函数返回X的正弦值。请考虑以下示例-
testdb=#SELECT SIN(90); +---------------------------------------------------------+ | SIN(90) | +---------------------------------------------------------+ | 0.893997 | +---------------------------------------------------------+ 1 row in set (0.00 sec)
SQRT(X)
此函数返回X的非负平方根。考虑以下示例-
testdb=#SELECT SQRT(49); +---------------------------------------------------------+ | SQRT(49) | +---------------------------------------------------------+ | 7 | +---------------------------------------------------------+ 1 row in set (0.00 sec)
SO(X)
该函数返回以弧度表示的参数X的切线。
testdb=#SELECT TAN(45); +---------------------------------------------------------+ | TAN(45) | +---------------------------------------------------------+ | 1.619775 | +---------------------------------------------------------+ 1 row in set (0.00 sec)
参考链接
https://www.learnfk.com/postgresql/postgresql-numeric-functions.html
标签:返回,set,PostgreSQL,0.00,无涯,Numeric,testdb,+-------------------------------------- From: https://blog.51cto.com/u_14033984/8981074