POWER() Function in MySQL
Last Updated :
01 Oct, 2020
POWER() function in MySQL is used to find the value of a number raised to the power of another number. It Returns the value of X raised to the power of Y.
Syntax :
POWER(X, Y)
Parameter : This method accepts two parameter which are described below :
- X : It specifies the base number.
- Y : It specifies the exponent number.
Returns : It returns the value of X raised to the power of Y.
Example-1 : Finding Power value when both base and exponent is positive using POWER() function.
SELECT POWER( 5, 4) AS Power_Value ;
Output :
Example-2 : Finding Power value when base and is positive but exponent is negative using POWER() function.
SELECT POWER( 2, -4) AS Power_Value ;
Output :
Example-3 : Finding Power value when base and is negative but exponent is positive using POWER() function.
SELECT POWER( -3, 3) AS Power_Value ;
Output :
Example-4 : Finding Power value when both base and exponent is negative using POWER() function.
SELECT POWER( -3, -4) AS Power_Value ;
Output :
Power_Value |
0.012345679012345678 |
Example-5 : The POWER function can also be used to find the power value between column data. To demonstrate create a table named.
Triangle.
CREATE TABLE Triangle(
Type VARCHAR(25) NOT NULL,
NoOfSides INT NOT NULL,
Base INT NOT NULL,
Height INT NOT NULL
);
Now inserting some data to the Triangle table :
INSERT INTO
Triangle(Type, NoOfSides, Base, Height )
VALUES
('Right-angled Triangle', 3, 4, 3 ),
('Right-angled Triangle', 3, 2, 5 ),
('Right-angled Triangle', 3, 1, 7 ),
('Right-angled Triangle', 3, 7, 9 ),
('Right-angled Triangle', 3, 4, 6 ),
('Right-angled Triangle', 3, 8, 3 ),
('Right-angled Triangle', 3, 10, 10 ) ;
Showing all data in Triangle Table -
Select * from Triangle ;
Type |
NoOfSides |
Base |
Height |
Right-angled Triangle |
3 |
4 |
3 |
Right-angled Triangle |
3 |
2 |
5 |
Right-angled Triangle |
3 |
1 |
7 |
Right-angled Triangle |
3 |
7 |
9 |
Right-angled Triangle |
3 |
4 |
6 |
Right-angled Triangle |
3 |
8 |
3 |
Right-angled Triangle |
3 |
10 |
10 |
Now, we are going to find the hypotenuse and area for each Right-angled Triangle.
SELECT
*,
sqrt(POWER(Base, 2) + POWER(Height, 2)) AS Hypotenuse,
0.5 * Base * Height as Area
FROM Triangle;
Output :
Type |
NoOfSides |
Base |
Height |
Hypotenuse |
Area |
Right-angled Triangle |
3 |
4 |
3 |
5 |
6.0 |
Right-angled Triangle |
3 |
2 |
5 |
5.385164807134504 |
5.0 |
Right-angled Triangle |
3 |
1 |
7 |
7.0710678118654755 |
3.5 |
Right-angled Triangle |
3 |
7 |
9 |
11.40175425099138 |
31.5 |
Right-angled Triangle |
3 |
4 |
6 |
7.211102550927978 |
12.0 |
Right-angled Triangle |
3 |
8 |
3 |
8.54400374531753 |
12.0 |
Right-angled Triangle |
3 |
10 |
10 |
14.142135623730951 |
50.0 |
Similar Reads
ORD() Function in MySQL ORD() function in MySQL is used to find the code of the leftmost character in a string . If the leftmost character is not a multibyte character, it returns ASCII value. And if the leftmost character of the string str is a multibyte character, ORD returns the code for that character, calculated from
3 min read
YEAR() Function in MySQL YEAR() function in MySQL is used to find year from the given date. If the date is NULL, the YEAR() function will return NULL. Otherwise, it returns value range from 1000 to 9999. Syntax : YEAR(date) Parameter : This method accepts one parameter as mentioned above and described below : date : The dat
3 min read
SPACE() Function in MySQL SPACE() function in MySQL is used to return a string consisting of specified empty space characters. Syntax : SPACE(num) Parameter : This method accepts one parameter as mentioned above and described below : num : It is an integer which indicates how many spaces are being contained. Returns : It ret
1 min read
PLSQL | POWER Function The POWER function is an inbuilt function in PLSQL which is used to return the calculated value when a raised to the bth power. If a is negative number, then b must be an integer. Syntax: POWER(a, b) Parameters Used: This function accepts two parameters a and b. If a is negative number, then b must
2 min read
SQRT() Function in MySQL The SQRT() function in MySQL calculates the square root of a non-negative number, returning NULL for negative inputs. It is a built-in function that provides high precision and is optimized for performance and making it ideal for mathematical and scientific applications.In the article, we will cover
3 min read