📜  MySQL math函数

📅  最后修改于: 2020-11-20 06:50:39             🧑  作者: Mango

MYSQL math函数

MySQL提供了多种功能,可满足多种算术目的。下表简要说明了每个功能:

Functions Description
ABS() The ABS() function returns the absolute value of the specified number.
ACOS() The ACOS() function is used to get the arc cosine of the given number.
SIGN() The SIGN() function is used to get a sign of the specified number.
SIN() The SIN() function is used to get the sine value of the given number.
SQRT() The SQRT() function is used to get the square root of the given number.
SUM() This function is used to sum the values of given expressions.
TAN() The TAN() function is used to get the tangent of the given number
TRUNCATE() The TRUNCATE() function is used to get the given number truncated up to given certain decimal places.
ASIN() The ASIN() function is used to get the arc sine of the given number.
ATAN2() The ATAN2 function is used to get the arc tangent of the specified numbers n and m.
ATAN() The ATAN() function is used to get the arc tangent of the specified number.
AVG() The AVG() function is used to get the average value from the given expression.
CEIL() The CEIL() function returns the smallest value which is greater than or equal to the specified number.
CEILING() The CEILING() function returns the smallest value which is greater than or equal to the given number.
COS() The COS() function is used to get the cosine of the given number.
COT() The COT() function is used to get the cotangent of the given number.
COUNT() The COUNT() function is used to get the total count for the specified column of the table.
DEGREES() DEGREES() function is used to convert the given radian number into a degree.
DIV() The DIV() function is used to find the integer division by dividing the number n by the number m.
EXP() The EXP() function is used to find e raised to the power of number i.e. enumber.
FLOOR() The FLOOR() function is used to find the greatest integer which is equal to or less than the specified number.
GREATEST() The GREATEST() function is used to get the largest number from the list.
LEAST() The LEAST() function is used to get the smallest number from the list.
LN() The LN() function is used to get the natural logarithm for the specified number.
LOG10() The LOG10() function is used to get the base-10 logarithm for the specified number.
LOG() The LOG() function is used to return either the natural logarithm of the given number if it has one parameter or specified base logarithm number if it has two parameters.
LOG2() The LOG2() function is used to get the base-2 logarithm for the specified number.
MAX() The MAX() function is used to get the maximum number of the given column name.
MIN() The MIN() function is used to get the minimum number of the given column name.
MOD() The MOD() function is used to get the remainder for the specified values.
PI() The PI() function is used to get the value of pi upto 6 decimal places.
POWER() The POWER() function is used to get the power for the specified values.
POW() The POW function is used to get the power for the specified values.
RADIANS() The RADIANS() function is used to convert the given degrees to radians.
RAND() The RAND() function is used to generate the random number.
ROUND() The ROUND() function is used to round off the specified number.

例子1

select pi();

输出:

mysql> SELECT PI();
+----------+
| PI()     |
+----------+
| 3.141593 |
+----------+
1 row in set (0.00 sec)

例子2

Select pow(3,2); 

输出:

mysql> SELECT POW(3, 2);
+-----------+
| POW(3, 2) |
+-----------+
|         9 |
+-----------+
1 row in set (0.00 sec)

例子3

select 4 % 3;  

输出:

mysql> SELECT 4 % 3;
+-------+
| 4 % 3 |
+-------+
|     1 |
+-------+
1 row in set (0.00 sec)