MySQL functions - Mathematical Functions

MySQL functions

MySQL MySQL database function is provided by built-in functions. These built-in functions can help users more easily handle the data in the table.

MySQL functions - Mathematical Functions

Mathematical Functions

MySQL mathematical functions are commonly used in a class of functions. Mainly for processing digital, including integer and floating point numbers and the like.

ABS (x) function

ABS (x) function is used for the absolute value.

example:

6 and obtaining the absolute value of -13
SELECT ABS (6), ABS ( -13);

MySQL functions - Mathematical Functions

FLOOR (x) function

The FLOOR (x) function returns the largest integer less than or equal to x.

example:

Returns the maximum integer greater than n
SELECT FLOOR (-3.14), CEILING ( 0.618);

MySQL functions - Mathematical Functions

RAND () function

RAND () function returns a random number between 0 and 1. But the RAND () Returns the number is completely random.

example:

select rand(20);

MySQL functions - Mathematical Functions

PI () function

PI () function returns the pi.

example:

select pi();

MySQL functions - Mathematical Functions

TRUNCATE (x, y) function

TRUNCATE (x, y) function returns the value of y to x reserved bits after the decimal point.

example:

select truncate(1.223,1);

MySQL functions - Mathematical Functions

ROUND (x) and the function ROUND (x, y) function

The ROUND (x) function returns the nearest integer x, i.e. the x-rounded off; the ROUND (x, y) function returns the value of y to x reserved bits after the decimal point, rounding processing is required truncation.

example:

Returns the rounded value of n, d retention decimal (default value d 0)
SELECT round (-1.23);

MySQL functions - Mathematical Functions

SQRT (x) function

SQRT (x) function is used to find the square root.

example:

select sqrt(4);

MySQL functions - Mathematical Functions

ceiling(n)

Returns the smallest integer less than n
select ceiling (1.23);

MySQL functions - Mathematical Functions

sign(n)

Returns the signs of the parameters (or -1, 0. 1)
SELECT SiN (PI ());

MySQL functions - Mathematical Functions

mod(n,m)

Modulo operation returns the remainder of n is divided by m (the same operator%)
PS: take the remainder of the dividend-related negative result, the dividend is positive at a positive, negative dividend is negative.
SELECT MOD (2,3), - 10 % 4;

MySQL functions - Mathematical Functions

pow (x, y) / power (x, y)

Back power y of x
select pow (2,2);

MySQL functions - Mathematical Functions

Guess you like

Origin blog.51cto.com/13760351/2481006