MySQL

来源:互联网 发布:telnet端口 编辑:程序博客网 时间:2024/06/06 16:55

MySQL numeric functions are used primarily for numeric manipulation and/or mathematical calculations. The following table details the numeric functions that are available in the MySQL implementation.
S. No. Name & Description
1 ABS()

Returns the absolute value of numeric expression.
2 ACOS()

Returns the arccosine of numeric expression. Returns NULL if the value is not in the range -1 to 1.
3 ASIN()

Returns the arcsine of numeric expression. Returns NULL if value is not in the range -1 to 1
4 ATAN()

Returns the arctangent of numeric expression.
5 ATAN2()

Returns the arctangent of the two variables passed to it.
6 BIT_AND()

Returns the bitwise AND all the bits in expression.
7 BIT_COUNT()

Returns the string representation of the binary value passed to it.
8 BIT_OR()

Returns the bitwise OR of all the bits in the passed expression.
9 CEIL()

Returns the smallest integer value that is not less than passed numeric expression
10 CEILING()

Returns the smallest integer value that is not less than passed numeric expression
11 CONV()

Converts numeric expression from one base to another.
12 COS()

Returns the cosine of passed numeric expression. The numeric expression should be expressed in radians.
13 COT()

Returns the cotangent of passed numeric expression.
14 DEGREES()

Returns numeric expression converted from radians to degrees.
15 EXP()

Returns the base of the natural logarithm (e) raised to the power of passed numeric expression.
16 FLOOR()

Returns the largest integer value that is not greater than passed numeric expression.
17 FORMAT()

Returns a numeric expression rounded to a number of decimal places.
18 GREATEST()

Returns the largest value of the input expressions.
19 INTERVAL()

Takes multiple expressions exp1, exp2 and exp3 so on.. and returns 0 if exp1 is less than exp2, returns 1 if exp1 is less than exp3 and so on.
20 LEAST()

Returns the minimum-valued input when given two or more.
21 LOG()

Returns the natural logarithm of the passed numeric expression.
22 LOG10()

Returns the base-10 logarithm of the passed numeric expression.
23 MOD()

Returns the remainder of one expression by diving by another expression.
24 OCT()

Returns the string representation of the octal value of the passed numeric expression. Returns NULL if passed value is NULL.
25 PI()

Returns the value of pi
26 POW()

Returns the value of one expression raised to the power of another expression
27 POWER()

Returns the value of one expression raised to the power of another expression
28 RADIANS()

Returns the value of passed expression converted from degrees to radians.
29 ROUND()

Returns numeric expression rounded to an integer. Can be used to round an expression to a number of decimal points
30 SIN()

Returns the sine of numeric expression given in radians.
31 SQRT()

Returns the non-negative square root of numeric expression.
32 STD()

Returns the standard deviation of the numeric expression.
33 STDDEV()

Returns the standard deviation of the numeric expression.
34 TAN()

Returns the tangent of numeric expression expressed in radians.
35 TRUNCATE()

Returns numeric exp1 truncated to exp2 decimal places. If exp2 is 0, then the result will have no decimal point.
ABS(X)

The ABS() function returns the absolute value of X. Consider the following example −

mysql> SELECT ABS(2);
+———————————————————+
| ABS(2) |
+———————————————————+
| 2 |
+———————————————————+
1 row in set (0.00 sec)

mysql> SELECT ABS(-2);
+———————————————————+
| ABS(2) |
+———————————————————+
| 2 |
+———————————————————+
1 row in set (0.00 sec)

ACOS(X)

This function returns the arccosine of X. The value of X must range between .1 and 1 or NULL will be returned. Consider the following example −

mysql> SELECT ACOS(1);
+———————————————————+
| ACOS(1) |
+———————————————————+
| 0.000000 |
+———————————————————+
1 row in set (0.00 sec)

ASIN(X)

The ASIN() function returns the arcsine of X. The value of X must be in the range of .1 to 1 or NULL is returned.

mysql> SELECT ASIN(1);
+———————————————————+
| ASIN(1) |
+———————————————————+
| 1.5707963267949 |
+———————————————————+
1 row in set (0.00 sec)

ATAN(X)

This function returns the arctangent of X.

mysql> SELECT ATAN(1);
+———————————————————+
| ATAN(1) |
+———————————————————+
| 0.78539816339745 |
+———————————————————+
1 row in set (0.00 sec)

ATAN2(Y,X)

This function returns the arctangent of the two arguments: X and Y. It is similar to the arctangent of Y/X, except that the signs of both are used to find the quadrant of the result.

mysql> SELECT ATAN2(3,6);
+———————————————————+
| ATAN2(3,6) |
+———————————————————+
| 0.46364760900081 |
+———————————————————+
1 row in set (0.00 sec)

BIT_AND(expression)

The BIT_AND function returns the bitwise AND of all bits in expression. The basic premise is that if two corresponding bits are the same, then a bitwise AND operation will return 1, while if they are different, a bitwise AND operation will return 0. The function itself returns a 64-bit integer value. If there are no matches, then it will return 18446744073709551615. The following example performs the BIT_AND function on the PRICE column grouped by the MAKER of the car −

mysql> SELECT
MAKER, BIT_AND(PRICE) BITS
FROM CARS GROUP BY MAKER
+———————————————————+
| MAKER BITS |
+———————————————————+
| CHRYSLER 512 |
| FORD 12488 |
| HONDA 2144 |
+———————————————————+
1 row in set (0.00 sec)

BIT_COUNT(numeric_value)

The BIT_COUNT() function returns the number of bits that are active in numeric_value. The following example demonstrates using the BIT_COUNT() function to return the number of active bits for a range of numbers −

mysql> SELECT
BIT_COUNT(2) AS TWO,
BIT_COUNT(4) AS FOUR,
BIT_COUNT(7) AS SEVEN
+—–+——+——-+
| TWO | FOUR | SEVEN |
+—–+——+——-+
| 1 | 1 | 3 |
+—–+——+——-+
1 row in set (0.00 sec)

BIT_OR(expression)

The BIT_OR() function returns the bitwise OR of all the bits in expression. The basic premise of the bitwise OR function is that it returns 0 if the corresponding bits match, and 1 if they do not. The function returns a 64-bit integer, and, if there are no matching rows, then it returns 0. The following example performs the BIT_OR() function on the PRICE column of the CARS table, grouped by the MAKER −

mysql> SELECT
MAKER, BIT_OR(PRICE) BITS
FROM CARS GROUP BY MAKER
+———————————————————+
| MAKER BITS |
+———————————————————+
| CHRYSLER 62293 |
| FORD 16127 |
| HONDA 32766 |
+———————————————————+
1 row in set (0.00 sec)

CEIL(X)
CEILING(X)

This function returns the smallest integer value that is not smaller than X. Consider the following example −

mysql> SELECT CEILING(3.46);
+———————————————————+
| CEILING(3.46) |
+———————————————————+
| 4 |
+———————————————————+
1 row in set (0.00 sec)

mysql> SELECT CEIL(-6.43);
+———————————————————+
| CEIL(-6.43) |
+———————————————————+
| -6 |
+———————————————————+
1 row in set (0.00 sec)

CONV(N,from_base,to_base)

The purpose of the CONV() function is to convert numbers between different number bases. The function returns a string of the value N converted from from_base to to_base. The minimum base value is 2 and the maximum is 36. If any of the arguments are NULL, then the function returns NULL. Consider the following example, which converts the number 5 from base 16 to base 2 −

mysql> SELECT CONV(5,16,2);
+———————————————————+
| CONV(5,16,2) |
+———————————————————+
| 101 |
+———————————————————+
1 row in set (0.00 sec)

COS(X)

This function returns the cosine of X. The value of X is given in radians.

mysql>SELECT COS(90);
+———————————————————+
| COS(90) |
+———————————————————+
| -0.44807361612917 |
+———————————————————+
1 row in set (0.00 sec)

COT(X)

This function returns the cotangent of X. Consider the following example −

mysql>SELECT COT(1);
+———————————————————+
| COT(1) |
+———————————————————+
| 0.64209261593433 |
+———————————————————+
1 row in set (0.00 sec)

DEGREES(X)

This function returns the value of X converted from radians to degrees.

mysql>SELECT DEGREES(PI());
+———————————————————+
| DEGREES(PI()) |
+———————————————————+
| 180.000000 |
+———————————————————+
1 row in set (0.00 sec)

EXP(X)

This function returns the value of e (the base of the natural logarithm) raised to the power of X.

mysql>SELECT EXP(3);
+———————————————————+
| EXP(3) |
+———————————————————+
| 20.085537 |
+———————————————————+
1 row in set (0.00 sec)

FLOOR(X)

This function returns the largest integer value that is not greater than X.

mysql>SELECT FLOOR(7.55);
+———————————————————+
| FLOOR(7.55) |
+———————————————————+
| 7 |
+———————————————————+
1 row in set (0.00 sec)

FORMAT(X,D)

The FORMAT() function is used to format the number X in the following format: ###,###,###.## truncated to D decimal places. The following example demonstrates the use and output of the FORMAT() function −

mysql>SELECT FORMAT(423423234.65434453,2);
+———————————————————+
| FORMAT(423423234.65434453,2) |
+———————————————————+
| 423,423,234.65 |
+———————————————————+
1 row in set (0.00 sec)

GREATEST(n1,n2,n3,……….)

The GREATEST() function returns the greatest value in the set of input parameters (n1, n2, n3, a nd so on). The following example uses the GREATEST() function to return the largest number from a set of numeric values −

mysql>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)

INTERVAL(N,N1,N2,N3,……….)

The INTERVAL() function compares the value of N to the value list (N1, N2, N3, and so on ). The function returns 0 if N < N1, 1 if N < N2, 2 if N

原创粉丝点击