Javatpoint Logo
Javatpoint Logo

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_ID Product_Name Product_Quantity Purchasing_Price Selling_Price Release_Date Product_Rating
104 P1 10 945 NULL 2022-04-30 NULL
202 P4 15 45 75 2022-01-28 5
103 P2 18 25 NULL 2022-02-18 4
111 P7 25 5 15 2021-12-25 9
210 P6 15 50 70 2021-10-15 NULL
212 P8 19 110 250 2022-01-28 4
112 P10 10 550 835 2022-04-11 NULL

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_ID log10_value_of_Product_ID
104 2.017
202 2.3054
103 2.013
111 2.0453
210 2.322
212 2.3263
112 2.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_Price log10_value_of_PurchasingPrice
945 2.9754
45 1.6532
25 1.398
5 0.699
50 1.699
110 2.0414
550 2.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_Rating log10_value_of_productrating
NULL
5 0.699
4 0.602
9 0.9542
NULL
4 0.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_Quantity log10_value_of_productquantity
10 1
15 1.176
18 1.2553
25 1.398
15 1.176
19 1.2788
10 1

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_Price log10_value_of_SellingPrice
NULL
75 1.875
NULL
15 1.176
70 1.845
250 2.398
835 2.9217






Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA