POWER Function in SQLThe 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 FunctionIn this POWER function, following are the two arguments:
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 functionExample 1: The following POWER function returns the value of base value 5 and exponent value 3: Output:
Example 2: The following POWER function returns the 625 in result: Output:
Example 3: This example uses the mathematical POWER function with the SQL 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:
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:
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:
Query 3: The following SELECT query uses the POWER function with the Product_Rating column of the above Product_Details table: Output:
Next TopicROUND Function in SQL |