POWER Function in SQL

The POWER is a mathematical function in SQL which returns the value of a number raised to the power of another number. In the power function, we have to pass the two number as the argument in which one number acts as exponent and other acts as the base.

Syntax of POWER String Function

In this POWER function, following are the two arguments:

  1. Number1: It acts as the base in the power function
  2. Number2: And, it acts as the exponent.

In Structured Query Language, we can also use the POWER function with the integer columns of the table as shown in the following block:

In this syntax, we used the POWER function with existing table of SQL. Here, we have to define the name and columns of that table on which we want to perform the POWER function.

Examples of POWER String function

Example 1: The following POWER function returns the value of base value 5 and exponent value 3:

Output:

POWER_of5
125

Example 2: The following POWER function returns the 625 in result:

Output:

POWER_of25
625

Example 3: This example uses the mathematical POWER function with the SQL table:
In this third example, we will create the new table through which we will perform the POWER function with the integer columns of the table:

The following shows the syntax to create the new table in SQL:

The following CREATE statement creates the Product_Details table for storing the price and quantity of products:

The following multiple INSERT queries insert the records of products with their selling and purchasing price into the Product_Details table:

The following SELECT statement displays the inserted records of the above Product_Details table:


Product_IDProduct_NameProduct_QuantityPurchasing_PriceSelling_PriceRelease_DateProduct_Rating
104P110.25094510502022-04-308
202P415.50045752022-01-285
103P218.250254752022-02-184
111P725.2505152021-12-259
210P612.65050702021-10-151
212P819.7501102502022-01-103
112P1024.9505508352022-04-118

Query 1: The following SELECT query uses the POWER function with the Product_Quantity and Power_ID columns of the above Product_Details table:

Output:

Product_IDPOWER2_of_IDProduct_QuantityPOWER1_ofquantity
1041081610.25010.250
2024080415.50015.500
1031060918.25018.250
1111232125.25025.250
2104410012.65012.650
2124494419.75019.750
1121254424.95024.950

Query 2: The following SELECT query uses the POWER function with the Purchasing_Price and Selling_Price columns of those products whose Product_ID is greater than 103 in the above Product_Details table:

Output:

Product_IDPurchasing_PricePOWER2_of_purchaseSelling_PricePOWER2_of_selling
10494589302510501102500
202452025755625
11152515225
210502500704900
2121101210025062500
112550302500835697225

Query 3: The following SELECT query uses the POWER function with the Product_Rating column of the above Product_Details table:

Output:

Product_RatingPOWER3_of_rating
8512
5125
464
9729
11
327
8512





Latest Courses