|
|
MySQL programming - MySQL mathematical FunctionsIn addition to the four basic arithmetic operations addition (+), Subtraction (-), Multiplication (*) and Division (/), MySQL also has the Modulo (%) operator. This calculates the remainder left after division. select 87 % 9; +--------+ | 87 % 9 | +--------+ | 6 | +--------+ 1 row in set (0.00 sec) MOD(x, y) select MOD(37, 13); +-------------+ | MOD(37, 13) | +-------------+ | 11 | +-------------+ 1 row in set (0.00 sec) ABS(x) select ABS(-4.05022); +---------------+ | ABS(-4.05022) | +---------------+ | 4.05022 | +---------------+ 1 row in set (0.00 sec) select ABS(4.05022); +--------------+ | ABS(4.05022) | +--------------+ | 4.05022 | +--------------+ 1 row in set (0.00 sec) SIGN(x) select SIGN(-34.22); +--------------+ | SIGN(-34.22) | +--------------+ | -1 | +--------------+ 1 row in set (0.00 sec) select SIGN(54.6); +------------+ | SIGN(54.6) | +------------+ | 1 | +------------+ 1 row in set (0.00 sec) select SIGN(0); +---------+ | SIGN(0) | +---------+ | 0 | +---------+ 1 row in set (0.00 sec) POWER(x,y) select POWER(4,3); +------------+ | POWER(4,3) | +------------+ | 64.000000 | +------------+ 1 row in set (0.00 sec) SQRT(x) select SQRT(3); +----------+ | SQRT(3) | +----------+ | 1.732051 | +----------+ 1 row in set (0.00 sec) ROUND(x) and ROUND(x,y) select ROUND(14.492); +---------------+ | ROUND(14.492) | +---------------+ | 14 | +---------------+ 1 row in set (0.00 sec) select ROUND(4.5002); +---------------+ | ROUND(4.5002) | +---------------+ | 5 | +---------------+ 1 row in set (0.00 sec) select ROUND(-12.773); +----------------+ | ROUND(-12.773) | +----------------+ | -13 | +----------------+ 1 row in set (0.00 sec) select ROUND(7.235651, 3); +--------------------+ | ROUND(7.235651, 3) | +--------------------+ | 7.236 | +--------------------+ 1 row in set (0.00 sec) FLOOR(x) select FLOOR(23.544); +---------------+ | FLOOR(23.544) | +---------------+ | 23 | +---------------+ 1 row in set (0.00 sec) select FLOOR(-18.4); +--------------+ | FLOOR(-18.4) | +--------------+ | -19 | +--------------+ 1 row in set (0.00 sec) CEILING(x) select CEILING(54.22); +----------------+ | CEILING(54.22) | +----------------+ | 55 | +----------------+ 1 row in set (0.00 sec) select CEILING(-62.23); +-----------------+ | CEILING(-62.23) | +-----------------+ | -62 | +-----------------+ 1 row in set (0.00 sec) TAN(x), SIN(x) and COS(x) select SIN(0); +----------+ | SIN(0) | +----------+ | 0.000000 | +----------+ 1 row in set (0.00 sec)
Page contents: Mysql programming - mysql mathematical Functions - mysql calculation functions - mysql guide
Page URL: http://www.webdevelopersnotes.com/tutorials/sql/ mysql_programming_mysql_mathematical_functions.php3
|
|