ln
The ln() function returns the natural logarithm of its argument.
|
|
Syntax
The syntax of the ln() function is:
LN (x)
x: A positive number, or an expression that evaluates to a positive number.
Examples
Basic ln() function
The following example returns the natural logarithm of 7.87653:
SELECT LN(7.87653);
The query returns:
+-------------+
| f |
+-------------+
| 2.0638874 |
+-------------+
Use ln() function with a table
This example combines the ln() function with a CREATE TABLE statement to obtain natural logarithmic values of a specific column:
-
Create a new table named
LNtablewith an integerinitValuecolumn.CREATE TABLE LNtable(initValue int); INSERT INTO LNtable(initValue) VALUES (75), (18), (28); -
Run this query to get the logarithm output of the column:
SELECT * ,LN(initValue) AS lnValue FROM LNtable; -
The query returns the initial value and its natural logarithm:
-
initValue: The original integer values. -
lnValue: The natural logarithm values.+------------+---------------------------+ | initValue | lnValue | +------------+---------------------------+ | 75 | 4.31748811353631 | | 18 | 2.8903717578961645 | | 28 | 3.332204510175204 | +------------+---------------------------+
-