MySQL (7)
1. mathematical functions
(1) absolute value function (ABS (x) and return the circumference rate function PI
ABS (X) returns the absolute value of X
Select abs (2), abs (-3.3), abs (1-9 );
Select pi ();
(2) square root function SQRT (x) and evaluate the remainder function MOD (x, y)
Select SQRT (9), SQRT (40), SQRT (-49 );
Select MOD (45.5), MOD (), MOD (6 );
(3) obtain the integer functions CEIL (x), CEILING (x) and FLOOR (x)
CEIL (x) and CEILING (x) have the same meaning. The return value is a minimum integer not less than x, and the return value is converted to a BIGINT.
Select CEIL (-3.35), CEILING (3.35 );
Use FLOOR (x) To return the maximum integer not greater than x. The return value is converted to a BIGINT.
Select floor (-3.35), floor (3.35 );
(4) functions RAND () and RAND (x) for obtaining random numbers)
RAND (x) returns a random floating point number v in the range of 0-1. If an integer parameter x is specified, it is used as the seed value to generate a recurring series.
Select RAND (), RAND ();
Select RAND (10), RAND (10 );
(5) Rounding functions ROUND (x), ROUND (x, y), and TRUNCATE (x, y)
ROUND (X) returns an integer closest to x, rounding x
Select round (-1.14), ROUND (-1.67), ROUND (1.14), ROUND (1.67 );
ROUND (x, y) returns the number close to x and retains the y digit after the decimal point. If y is negative, the x value is retained to the y digit on the left of the decimal point.
Select round (1.38, 1), ROUND (1.38, 0), ROUND (232.38,-1), ROUND (232.38,-2 );
TRUNCATE (x, y) returns the number rounded to the y digit after the decimal point. If y is 0, no decimal point or decimal point is returned. If y is a negative number, the system truncates all the low positions after the start of the y decimal point on the left of x.
Select trunacate (1.31, 1), TRUNCATE (1.99, 1), TRUNCATE (1.99, 0)