# DIV Function in SQL

The DIV is a string function in SQL which returns the quotient by dividing the first number from second number.

### Syntax of DIV Function

In 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 function

Example 1: This example gets the quotient by dividing 101 by 4:

Output:

Division_of_101by4
25

Example 2: This example divides 101 by 4 and returns the quotient in result:

Output:

Division_of_2by2
1

Example 3: This example divides 8 by 5 and returns the quotient in result:

Output:

Division_of_8by5
1

Example 4: This example divides 255 by 200 and returns the quotient in result:

Output:

Division_of_255by200
1

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:

104P110945NULL2022-04-30NULL
202P41545752022-01-285
103P21825NULL2022-02-184
111P7255152021-12-259
210P61550702021-10-15NULL
212P8191102502022-01-284
112P10105508352022-04-11NULL

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:

Product_IDDivision_of_ProductID_by100
1041
2022
1031
1111
2102
2122
1121

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:

9451094NULL10-
4515375155
25181NULL18-
525015250
5015370154
1101952501913
55010558351083

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:

Product_RatingDivision_ofratingby2
NULL-
52
42
94
NULL-
42
NULL-