POWER Function - SQL
Overview
The POWER function in SQL returns the value of a numeric expression raised to a specified power. It is useful for performing exponential calculations.
Example:
SELECT
POWER(2, 3)
SELECT
POWER(base, exponent)
Syntax:
base
is the numeric expression to be raised to the power of exponent
.
exponent
is the power to which the base
is raised.
Sample Data:
first_name | vacation_days |
---|---|
Frank | 5 |
Jane | 2 |
Ashley | 3 |
Glenn | -3 |
Kelly | 2 |
Richard | -7 |
George | 2 |
Kyle | 1 |
James | -2 |
Gustavo | -10 |
Example: Hard-coded value
In this example, we are returning 2 to the power of 3, the final output is 8.
Example: Query without the WHERE Statement
In this example, we are returning the vacation_days column to the power of 2.
Example: Query with the WHERE Statement
In this example, we are returning the vacation_days column to the power of 2 where the first_name equals ‘Kelly.’