Skip to content
Related Articles

Related Articles

Improve Article
EXP() Function in MySQL
  • Last Updated : 30 Oct, 2020

EXP() function in MySQL is used to returns E raised to the power of a specified number. Here E(2.718281…) is the base of the natural logarithm.

Syntax :

EXP(X)

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

X – A specified number which will be used as a power of E.

Returns : It returns E raised to the power of the given number X.



Example-1 :
Calculating e raised to the power of 1 using EXP() function.

SELECT EXP(1) AS Exp_Val ;

Output :

EXP_VAL
2.718281828459045

Example-2 :
Calculating e raised to the power of -3 using EXP() function.

SELECT EXP(-3) AS Exp_Val ;

Output :

EXP_VAL
0.049787068367863944

Example-3 :
The EXP function can also be used in 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
('ASUS ROG', 80000.00, 100000.00, 4.00 ),
('DELL INSPIRON', 75000.00, 90000.00, 3.00 ),
('ACER PREDATOR', 100000.00, 134000.00, 2.50 ),
('LENOVO LEGION', 90000.00, 118000.00, 1.50 ),
('HP OMEN', 70000.00, 85000.00, 5.00) ;

Showing all data in Product Table –

Select * from Product;
PRODUCT_IDPRODUCT_NAMEBUYING_PRICESELLING_PRICESERVICE_GRADE
1ASUS ROG80000.00100000.004.00
2DELL INSPIRON75000.0090000.003.00
3ACER PREDATOR100000.00134000.002.50
4LENOVO LEGION90000.00118000.001.50
5HP OMEN70000.0085000.005.00

Now, we are going to find exp values for all the records present in the Service_grade column.

Select Product_id, Product_name, Buying_price,  
Selling_price, Service_grade,
EXP(Service_grade) AS EXPGRADE  
FROM Product;

Output :

PRODUCT_IDPRODUCT_NAMEBUYING_PRICESELLING_PRICESERVICE_GRADEEXPGRADE
1ASUS ROG80000.00100000.004.0054.598150033144236
2DELL INSPIRON75000.0090000.003.0020.085536923187668
3ACER PREDATOR100000.00134000.002.5012.182493960703473
4LENOVO LEGION90000.00118000.001.504.4816890703380645
5HP OMEN70000.0085000.005.00148.4131591025766
My Personal Notes arrow_drop_up
Recommended Articles
Page :