LOG10() Function in SQL Server
The LOG10() function in SQL Server is used to return the base-10 logarithm of a given numeric expression. It takes a single argument, which must be a positive numeric expression.
Syntax:
LOG10 ( numeric_expression )
Example: Suppose we have a table named "sales" with the following data:
id | product | sales |
---|---|---|
1 | A | 100 |
2 | B | 1000 |
3 | C | 500 |
4 | D | 250 |
To find the base-10 logarithm of the sales column, we can use the following query:
SELECT product, LOG10(sales) as log_sales
FROM sales;
This will give us the following result:
product | log_sales |
---|---|
A | 2 |
B | 3 |
C | 2.69897 |
D | 2.39794 |
Another way to calculate the base-10 logarithm is by using the formula:
LOG10(x) = LOG(x) / LOG(10)
Using this formula, we can rewrite the above query as:
SELECT product, LOG(sales) / LOG(10) as log_sales
FROM sales;
This will give us the same result as before.