DIV Function in SQLThe DIV is a string function in SQL which returns the quotient by dividing the first number from second number. Syntax of DIV FunctionIn the DIV syntax, Number1 is the dividend and Number2 is the divisor. In the Structured Query Language, we can also use the DIV function with the columns of the table as shown in the following block: In this syntax, we have to define the name and columns of that table on which we want to perform the DIV function. Examples of DIV functionExample 1: This example gets the quotient by dividing 101 by 4: Output:
Example 2: This example divides 101 by 4 and returns the quotient in result: Output:
Example 3: This example divides 8 by 5 and returns the quotient in result: Output:
Example 4: This example divides 255 by 200 and returns the quotient in result: Output:
Example 5: This example uses the DIV function with the SQL table. In this example, we will create the new table through which we will perform the DIV function on the 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 DIV function with the Product_Quantity column of the above Product_Details table: This query divides each product_id by 100 and returns the quotient after division. Output:
Query 2: The following SELECT query uses the DIV function with the and Purchasing_Price and Selling_Price column of the above Product_Details table: This query divides the purchasing price and selling price of each product by product quantity and returns the quotient. Output:
Query 3: The following SELECT query uses the DIV function with the Product_Rating column of the above Product_Details table: This query divides each rating of product by 2 and returns the quotient after division. Output:
Next TopicLEAST Function in SQL |