LOG
Returns the natural logarithm of a number or its logarithm to the given base.
MySQL 8.4
LOG([base, ]num)- [ ]optional part
- base
- Logarithm base, e by defaultDOUBLEOptional
- num
- Number to take the logarithm ofDOUBLE
Return value
A floating-point number (DOUBLE); NULL if num ≤ 0, base ≤ 0 or base = 1
Examples
Logarithm to base 2
MySQL 8.4
SELECT LOG(2, 8);Natural logarithm
MySQL 8.4
SELECT LOG(100);Details
Common bases have their own functions: LN is the natural logarithm, LOG2 and LOG10 use base 2 and 10. Unlike PostgreSQL, where LOG(num) with one argument is the base-10 logarithm, here it is the natural logarithm.