SQLite POW() Function
The SQLite POW() function returns the base raise to the power of exponent. In special cases it returns the following:
- If the exponent is zero, then 1 is returned.
The POW() function is a synonym for the POWER() function.
Syntax
POW(base, exponent)
Parameters
base |
Required. Specify the base. |
exponent |
Required. Specify the exponent. |
Return Value
Returns the base raise to the power of exponent.
Example 1:
The example below shows the usage of POW() function.
SELECT POW(5, 2); Result: 25.0 SELECT POW(3, 5); Result: 243.0 SELECT POW(5.5, 2); Result: 30.25 SELECT POW(5.5, 2.1); Result: 35.872500303491 SELECT POW(5, -1); Result: 0.2 SELECT POW(5, 0); Result: 1.0 SELECT POW(0, 5); Result: 0.0
Example 2:
Consider a database table called Sample with the following records:
Data | x |
---|---|
Data 1 | 0.5 |
Data 2 | 1 |
Data 3 | 5 |
Data 4 | 10 |
Data 5 | 50 |
The statement given below can be used to calculate the square root of column x.
SELECT *, POW(x, 0.5) AS POW_Value FROM Sample;
This will produce the result as shown below:
Data | x | POW_Value |
---|---|---|
Data 1 | 0.5 | 0.707106781186548 |
Data 2 | 1 | 1.0 |
Data 3 | 5 | 2.23606797749979 |
Data 4 | 10 | 3.16227766016838 |
Data 5 | 50 | 7.07106781186548 |
Example 3:
Consider a database table called Sample with the following records:
Data | x | y |
---|---|---|
Data 1 | 0.5 | 2 |
Data 2 | 1 | 3 |
Data 3 | 5 | 4 |
Data 4 | 10 | 3 |
Data 5 | 50 | 3 |
To calculate the records of column x raised to the power of records of column y, the following query can be used:
SELECT *, POW(x, y) AS POW_Value FROM Sample;
This will produce the result as shown below:
Data | x | y | POW_Value |
---|---|---|---|
Data 1 | 0.5 | 2 | 0.25 |
Data 2 | 1 | 3 | 1.0 |
Data 3 | 5 | 4 | 625.0 |
Data 4 | 10 | 3 | 1000.0 |
Data 5 | 50 | 3 | 125000.0 |
❮ SQLite Functions