LOG10 Function - SQL


Overview


The LOG10 function in SQL returns the base-10 logarithm of a given numeric expression. It is useful for logarithmic calculations where the base is 10.

Example:

SELECT LOG10(100)

Syntax:

SELECT LOG10(numeric_expression)

numeric_expression is the numeric value for which you want to calculate the base-10 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 base-10 logarithm of 100, the final output is 2.


Example: Query without the WHERE Statement


In this example, we are returning the base-10 logarithm for all of the values in the vacation_days column.


Example: Query with the WHERE Statement


In this example, we are returning the base-10 logarithm for the values in the vacation_days column where the first_name equals ‘Kelly.’