Javatpoint Logo
Javatpoint Logo

POW Function in SQL

The POW is a mathematical function in SQL which returns the value of a number raised to the power of another number. This function is similar to the POWER function. In the POW 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 POW String Function

In this POW 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 POW function with the integer columns of the table as shown in the following block:

In this syntax, we used the POW 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 POW function.

Examples of POW String function

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

Output:

power_of5
125

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

Output:

Power_of25
625

Example 3: This example uses the mathematical POW function with the SQL table: In this third example, we will create the new table through which we will perform the POW 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_ID Product_Name Product_Quantity Purchasing_Price Selling_Price Release_Date Product_Rating
104 P1 10.250 945 1050 2022-04-30 8
202 P4 15.500 45 75 2022-01-28 5
103 P2 18.250 25 475 2022-02-18 4
111 P7 25.250 5 15 2021-12-25 9
210 P6 12.650 50 70 2021-10-15 1
212 P8 19.750 110 250 2022-01-10 3
112 P10 24.950 550 835 2022-04-11 8

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

This query shows the greatest value from the product id and quantity of each product.

Output:

Product_ID POWER2_of_ID Product_Quantity POWER1_ofquantity
104 10816 10.250 10.250
202 40804 15.500 15.500
103 10609 18.250 18.250
111 12321 25.250 25.250
210 44100 12.650 12.650
212 44944 19.750 19.750
112 12544 24.950 24.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_ID Purchasing_Price POWER2_of_purchase Selling_Price POWER2_of_selling
104 945 893025 1050 1102500
202 45 2025 75 5625
111 5 25 15 225
210 50 2500 70 4900
212 110 12100 250 62500
112 550 302500 835 697225

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

Output:

Product_Rating POWER3_of_rating
8 512
5 125
4 64
9 729
1 1
3 27
8 512






Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA