SQRT Function in SQLThe SQRT is a SQL function of mathematics which gives the square root of the given number. Suppose, the number is 25, then this function returns 5. Syntax of SQRT FunctionIn the SQRT syntax, we have to pass that number whose square root we want to find. In the Structured Query Language, we can also use the SQRT function with the fields of the table as shown in the following block: In this syntax, we have to define the name and column of that table on which we want to perform the SQRT function. Examples of SQRT functionExample 1: This example returns the square root of the specified number: Output:
Example 2: This example returns the square root of the specified number: Output:
Example 3: This example returns the square root of 8: Output:
Example 4: This example returns the SQRTary representation of 255: Output:
Example 5: This example returns the square root of theNULL value: Output:
Example 6: This example returns the square root of numbers from 21 to 30: Output:
Example 7: This example uses the SQRT 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 SQRT function with the Product_Quantity column of the above Product_Details table: This query shows the Square root of product id of each product. Output:
Query 2: The following SELECT query uses the SQRT function with the and Purchasing_Price and Selling_Price column of the above Product_Details table: This query shows the square root of the purchasing and selling price of each product. Output:
Query 3: The following SELECT query uses the SQRT function with the Product_Rating column of the above Product_Details table: This query shows the square root of rating of each product in the above table. Output:
Next TopicSQUARE Function in SQL |