ROUND Function in SQLThe SQL ROUND function rounds the specified number till the particular decimal places. Syntax of ROUND String FunctionIn this ROUND function, following are the three arguments:
In Structured Query Language, we can also use the ROUND function with the integer columns of the table as shown in the following block: In this syntax, we used the ROUND 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 ROUND function. Examples of ROUND String functionExample 1: The following round function rounds the number to -1 decimal places: Output:
Example 1: The following round function rounds the number to 2 decimal places with third argument which is non-zero: Output:
Example 3: This example uses the mathematical ROUND function with the SQL table: In this third example, we will create the new table through which we will perform the ROUND 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:
Query 1: The following SELECT query uses the ROUND function with the Product_Quantity column of the above Product_Details table: Output:
Query 2: The following SELECT query uses the ROUND 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 ROUND function with the Product_Quantity column of the above Product_Details table: This function uses the non-zero value, i.e., 1 to the third argument in round function. Output:
Next TopicSUM Function in SQL |