Related Articles

Related Articles

LOG10() Function in MySQL
  • Last Updated : 20 Oct, 2020

LOG10() function in MySQL is used to calculate the natural logarithm of a specific number with base 10. The number must be greater than 0, otherwise it will return NULL.

Syntax :

LOG10(X)

Parameter : This method accepts one parameter as mentioned above in the syntax and described below :

  • X – A number whose logarithm value with base 10 we want to calculate. It should be positive number.

Returns : It returns the natural logarithm of given number x with base 10.

Example-1 :
The logarithm of the given number with base 10 using the LOG10() function.



SELECT LOG10(1000) AS Log10_Val ;

Output :

Log10_Val
3


Example-2 :
The logarithm of 0 using LOG10() function.

SELECT LOG10(0) AS Log10_Val ;

Output :

Log10_Val
NULL


Example-3 :
The LOG10 function can also be used to find the logarithmic value with base 10 of a column data. To demonstrate create a table named Product.

CREATE TABLE Product(
Product_id INT AUTO_INCREMENT,  
Product_name VARCHAR(100) NOT NULL,
Buying_price DECIMAL(13, 2) NOT NULL,
Selling_price DECIMAL(13, 2) NOT NULL,
Service_grade Decimal(6, 2) NOT NULL,
PRIMARY KEY(Product_id)
);

Now inserting some data to the Product table –

INSERT INTO  
Product(Product_name, Buying_price, Selling_price, Service_grade)
VALUES
('Touring Bike', 2019.00, 3009.6, 5.89 ),
('Mountain Bike', 3019.50, 4000.56, 10.00 ),
('Road Bike', 1019.20, 2000.56, -0.89 ),
('Road Bicycle', 1419.50, 1800.56, -1.50 ),
('Racing Bicycle', 3000.50, 4500.56, 5.00) ;

Showing all data in Product Table –

Select * from Product;
PRODUCT_ID PRODUCT_NAME BUYING_PRICE SELLING_PRICE SERVICE_GRADE
1 Touring Bike 2019.00 3009.6 5.89
2 Mountain Bike 3019.50 4000.56 10.00
3 Road Bike 1019.20 2000.56 -0.89
4 Road Bicycle 1419.50 1800.56 -1.50
5 Racing Bicycle 3000.50 4500.56 5.00

Now, we are going to find the logarithmic values with base 10 for all the records present in the Service_grade column.

Select Product_id, Product_name, Buying_price, 
Selling_price, Service_grade,
LOG10(Service_grade) AS GRADELOG10  
FROM Product;

Output :

PRODUCT_ID PRODUCT_NAME BUYING_PRICE SELLING_PRICE SERVICE_GRADE GRADELOG10
1 Touring Bike 2019.00 3009.6 5.89 0.7701152947871016
2 Mountain Bike 3019.50 4000.56 10.00 1
3 Road Bike 1019.20 2000.56 -0.89 NULL
4 Road Bicycle 1419.50 1800.56 -1.50 NULL
5 Racing Bicycle 3000.50 4500.56 5.00 0.6989700043360189
My Personal Notes arrow_drop_up
Recommended Articles
Page :