LN Function - SQL


Overview


The LN function in SQL returns the natural logarithm of a given numeric expression. It is useful for logarithmic calculations where the base is e (approximately 2.718).

Example:

SELECT LN(2.718281828459045)

Syntax:

SELECT LN(numeric_expression)

numeric_expression is the numeric value for which you want to calculate the natural logarithm.

Sample Data:

first_name vacation_days
Frank 5
Jane 2
Ashley 3
Glenn -3
Kelly 2
Richard -7
George 2
Kyle 1
James -2
Gustavo -10

Example: Hard-coded value


In this example, we are returning the natural logarithm of 2.718281828459045 with the final output being 1.


Example: Query without the WHERE Statement


In this example, we are returning the natural logarithm of the values in the vacation_days column.


Example: Query with the WHERE Statement


In this example, we are returning the natural logarithm of the values in the vacation_days column where the first_name equals ‘Kelly.’