LOG10 Function in SQL

The LOG10() is a mathematics function which returns the logarithm of the specified number to base 10.

Syntax of LOG10 Function

In this SELECT syntax, we have to pass that numeric number in the function whose log 10 value we want to find.

In the Structured Query Language, we can also use the LOG10 function in SELECT query with the table field:

In this SELECT query, we have to define the name and field of that table on which we want to perform the LOG10 function.

Examples of LOG10 function

Example 1: This example gets the log 10 of 1:

Output:

Logarithm_of_1
0.0

Example 2: This example returns the logarithm of 10 by base 10 in the output:

Output:

Logarithm_of_10bybase_10
1

Example 3: This example returns the logarithm of 8 by base 10 in the output:

Output:

Logarithm_of_8bybase_10
0.903

Example 4: This example returns the logarithm of 255 by base 10 in the output:

Output:

Logarithm_of_255bybase_10
2.4065

Example 5: This example uses the LOG10 function with the SQL table. In this example, we will create the new table through which we will perform the LOG10 function on the numeric fields of the table.

The following shows the syntax to create the new table in SQL:

The following CREATE statement creates the Product_Details table for storing the price and quantity of products:

The following multiple INSERT queries insert the records of products with their selling and purchasing price into the Product_Details table:

The following SELECT statement displays the inserted records of the above Product_Details table:


Product_IDProduct_NameProduct_QuantityPurchasing_PriceSelling_PriceRelease_DateProduct_Rating
104P110945NULL2022-04-30NULL
202P41545752022-01-285
103P21825NULL2022-02-184
111P7255152021-12-259
210P61550702021-10-15NULL
212P8191102502022-01-284
112P10105508352022-04-11NULL

Query 1: The following SELECT query uses the LOG10 function with the Product_Quantity column of the above Product_Details table:

This query shows the log 10 value of id of each product.

Output:

Product_IDlog10_value_of_Product_ID
1042.017
2022.3054
1032.013
1112.0453
2102.322
2122.3263
1122.0492

Query 2: The following SELECT query uses the LOG10 function with the and Purchasing_Price column of the above Product_Details table:

This query shows the log 10 value of purchasing price of each product.

Output:

Purchasing_Pricelog10_value_of_PurchasingPrice
9452.9754
451.6532
251.398
50.699
501.699
1102.0414
5502.7404

Query 3: The following SELECT query uses the LOG10 function with the Product_Rating column of the above Product_Details table:

This query shows the log 10 value of rating of each product from the above table.

Output:

Product_Ratinglog10_value_of_productrating
NULL
50.699
40.602
90.9542
NULL
40.602
NULL

Query 4: The following SELECT query uses the LOG10 function with the Product_Quantity column of the above Product_Details table:

This query shows the log 10 value of quantity of each product from the above table.

Output:

Product_Quantitylog10_value_of_productquantity
101
151.176
181.2553
251.398
151.176
191.2788
101

Query 5: The following SELECT query uses the LOG10 function with the and Purchasing_Price and Selling_Price column of the above Product_Details table:

This query shows the log 10 value of selling price of each product.

Output:

Selling_Pricelog10_value_of_SellingPrice
NULL
751.875
NULL
151.176
701.845
2502.398
8352.9217





Latest Courses