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_ID |
PRODUCT_NAME |
BUYING_PRICE |
SELLING_PRICE |
SERVICE_GRADE |
1 |
ASUS ROG |
80000.00 |
100000.00 |
4.00 |
2 |
DELL INSPIRON |
75000.00 |
90000.00 |
3.00 |
3 |
ACER PREDATOR |
100000.00 |
134000.00 |
2.50 |
4 |
LENOVO LEGION |
90000.00 |
118000.00 |
1.50 |
5 |
HP OMEN |
70000.00 |
85000.00 |
5.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_ID |
PRODUCT_NAME |
BUYING_PRICE |
SELLING_PRICE |
SERVICE_GRADE |
EXPGRADE |
1 |
ASUS ROG |
80000.00 |
100000.00 |
4.00 |
54.598150033144236 |
2 |
DELL INSPIRON |
75000.00 |
90000.00 |
3.00 |
20.085536923187668 |
3 |
ACER PREDATOR |
100000.00 |
134000.00 |
2.50 |
12.182493960703473 |
4 |
LENOVO LEGION |
90000.00 |
118000.00 |
1.50 |
4.4816890703380645 |
5 |
HP OMEN |
70000.00 |
85000.00 |
5.00 |
148.4131591025766 |
Similar Reads
ELT() Function in MySQL
In this article, we are going to cover ELT function with examples. In ELT function, number field will state that how many strings will be there. ELT function in MySQL is used to returns the string which is at index number specified in the argument list. In this function there is number field and str
1 min read
FIELD() function in MySQL
FIELD() : This function helps in returning the position of a value in the given value list. If the user passes string values as the argument of FIELD() function, then the search will be performed as string values. And, If the user passes numeric values as the argument of FIELD() function, then searc
2 min read
FIELD() Function in MySQL
FIELD() function : This function in MySQL is used to return the index position of a specified value in a list of given values. For example, if the given list is ("3", "1", "2") and the value is "1" for which index position is going to be search, then this function will return 2 as the index position
2 min read
DAY() Function in MySQL
DAY() function : This function in MySQL is used to return the day of the month for a specified date (a number from 1 to 31). This function equals the DAYOFMONTH() function. Syntax : DAY(date) Parameter : This method accepts a parameter which is illustrated below : date : Specified date to extract th
1 min read
DIV() Function in MySQL
DIV() function : This function in MySQL is used to return a quotient (integer) value when integer division is done. For example, when 7 is divided by 3, then 2 will be returned. Syntax : SELECT x DIV y; Parameter : This method accepts two parameters as given below as follows. x - Specified dividend
1 min read
COT() Function in MySQL
COT() function : This function in MySQL is used to return the cotangent of a specified number. If the specified number is 0, an error or NULL will be returned. In a right triangle, the cotangent of an angle is the length of it's adjacent side divided by the length of the opposite side. Similarly, th
1 min read
EXPORT_SET() function in MySQL
EXPORT_SET() : This function helps to return a string which will show the bits in number. The function requires 5 arguments for its functioning. The function converts first argument i.e integer to binary digits, then returns âonâ if binary digit is 1 and âoffâ if binary digit is 0. Syntax : EXPORT_S
2 min read
MySQL IF( ) Function
The MySQL IF() function is a control flow function that returns different values based on the result of a condition. IF() Function in MySQLThe IF() function in MySQL returns a value if the condition is TRUE and another value if the condition is FALSE. The MySQL IF() function can return values that c
2 min read
CEILING() Function in MySQL
CEILING() function :This function in MySQL is used to return the smallest integer value that is greater than or equal to a specified number. For example, if the specified number is 4.6, this function will return the integer value of 5 that is greater than 4.6 or if a specified number is 5, this func
2 min read
DAYNAME() Function in MySQL
DAYNAME() function : This function in MySQL is used to return the weekday name for a specified date. Syntax : DAYNAME(date) Parameter : This method accepts a parameter which is illustrated below as follows. date - Specified date to extract the weekday name from Returns : It returns the weekday name
1 min read