SQL matematické funkcie podľa databáz
SQL -> Funkcie -> matematické funkcie
Prepnúť na rozdelenie podľa funkcií
Function | DB2 | SQLite | MySQL | PostgreSQL | Firebird | OpenLink Virtuoso | Oracle | MSSQL |
---|---|---|---|---|---|---|---|---|
Absolute value of x | ABS(x) | ABS(x) | ABS(x) | ABS(x) | ABS(x) | ABS(x) | ABS(x) | ABS(x) |
Sign of number x | SIGN(x) | N/A | SIGN(x) | SIGN(x) | SIGN(x)[1] | SIGN(x) | SIGN(x) | SIGN(x) |
Modulus (remainder) of x / y | MOD(x, y) | x % y | x % y, MOD(x, y) | x % y, MOD(x, y) | MOD(x,y) | MOD(x,y) | MOD(x, y) | x % y |
Smallest integer >= x | CEILING(x), CEIL(x) | N/A | CEILING(x), CEIL(x) | CEILING(x), CEIL(x) | CEILING(x) | CEILING(x) | CEIL(x) | CEILING(x) |
Largest integer <= x | FLOOR(x) | N/A | FLOOR(x) | FLOOR(x) | FLOOR(x) | FLOOR(x) | FLOOR(x) | FLOOR(x) |
Round x (to precision of d digits) | ROUND(x, d) | ROUND(x[, d]) | ROUND(x[, d]) | ROUND(x[, d]) | ROUND(x,d)[1] | ROUND(x) | ROUND(x[, d]) | ROUND(x[, d]) |
Truncate x to n decimal places | TRUNCATE(x, n), TRUNC(x, n) | N/A | TRUNCATE(x[, dn) | TRUNC(x[, y]) | N/A | N/A | TRUNC | N/A |
Square root | SQRT(x) | N/A | SQRT(x) | SQRT(x) | SQRT(x) | SQRT(x) | SQRT(x) | SQRT(x) |
Exponent of x (ex) | EXP(x) | N/A | EXP(x) | EXP(x) | ? | EXP(x) | EXP(x) | EXP(x) |
Power (xy) | POWER(x, y) | N/A | POWER(x, y), POW(x, y) | POWER(x, y) | POWER(x, y)[1] | POWER(x,y) | POWER(x, y) | POWER(x, y) |
Natural logarithm of x | LN(x) | N/A | LN(x) | LN(x) | LN(x) | LOG(x) | LN(x) | LOG(x) |
Logarithm, any base | LOG(b, x) | N/A | LOG(b, x) | LOG(b, x) | LOG(b, x) | LOG(x) | LOG(x) | N/A |
Logarithm, base 10 | LOG10(x) | N/A | LOG10(x) | LOG(x) | LOG10(x) | LOG(x) | LOG(x) | LOG10(x) |
Randomize, set seed to x | RAND(x) | N/A | RAND(x) | SETSEED(x) | ? | RANDOMIZE([x]) | random()[2] | RAND(x) |
Generate random number | RAND() | RANDOM() | RAND() | RANDOM() | RAND() | RND() | N/A | RAND() |
Highest number in list | N/A | MAX(list) | GREATEST(list) | GREATEST(list) | MAX() | MAX(list) | GREATEST(list) | N/A |
Lowest number in list | N/A | MIN(list) | LEAST(list) | LEAST(list) | MIN(list) | MIN(list) | LEAST(list) | N/A |
Convert number if NULL | COALESCE | COALESCE | COALESCE | COALESCE | ISNULL | COALESCE | COALESCE |
Firebird users need to install rFunc library for some functions, such as SIGN, ROUND, POWER, LASTDAYMONTH.
The random() function in Oracle can be found in the built-in DBMS package dbms_random.