FLOOR Function in SQL

The FLOOR numeric function in Structured Query Language returns the largest integer value which is smaller than or equal to the given number.

Syntax of FLOOR Function

Syntax1: This syntax uses the FLOOR function with the column name of the SQL table:

In this first syntax, we have to specify the name of that integer column on which we want to execute the FLOOR numeric function.

Syntax2: This syntax uses the FLOOR function with the integer or decimal value:

Examples of FLOOR function

Example 1: This example returns the floor value of the specified number:

Output:

floor_Value_of_0.5
0

Example 2: This example returns the floor value of the specified number:

Output:

floor_Value_of_10.9
10

Example 3: This example returns the floor value of 1.1:

Output:

floor_Value_of_1.1
1

Example 4: This example returns the floor value of all the numbers between 21 and 30:

Output:

21.822.923.5824.5525.052627.12528.9829.8930.02
21222324252627282930

Example 5: This example uses the floor function with the SQL table.

In this example, we will create the new table through which we will perform the floor 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:


Product_IDProduct_NameProduct_QuantityPurchasing_PriceSelling_PriceRelease_DateProduct_Rating
0.1P136.25015.5NULL2022-04-30NULL
0.2P475.5002.4514.82022-01-289.25
0.3P268.35095.8512.2502022-02-189.15
0.4P748.85085.355NULL2021-12-258.45
1.5P635.9000.50.5002021-10-15NULL
2.6P820.750112.1109.952022-01-289.9
0.7P1012.250999.5500.2582022-04-11NULL

Query 1: The following SELECT query uses the floor function with the Product_ID column of the above Product_Details table:

SELECT Product_ID, FLOOR(Product_ID) AS floor_Value_of_Product_ID FROM Product_Details;

This query shows the floor value of product id of each product.

Output:

Product_IDfloor_Value_of_Product_ID
0.10
0.20
0.30
0.40
1.51
2.62
0.70

Query 2: The following SELECT query uses the floor function with the and Purchasing_Price and Selling_Price column of the above Product_Details table:

SELECT Purchasing_Price, FLOOR(Purchasing_Price) AS floor_Value_of_PurchasingPrice, Selling_Price, FLOOR(Selling_Price) AS floor_Value_of_SellingPrice FROM Product_Details;

This query shows the floor value of Purchasing and selling price of each product from the above table.

Output:

Purchasing_Pricefloor_Value_of_PurchasingPriceSelling_Pricefloor_Value_of_SellingPrice
15.515NULL-
2.45214.814
95.859512.25012
85.35585NULL-
0.500.5000
112.1101129.959
999.5509990.2580

Query 3: The following SELECT query uses the floor function with the Product_Rating column of the above Product_Details table:

SELECT floor(Product_Rating) AS floor_Value_of_productrating FROM Product_Details;

This query shows the floor value of rating of each product from the above table.

Output:

Product_Ratingfloor_Value_of_productrating
NULL-
9.259
9.159
8.458
NULL-
9.99
NULL-

Query 4: The following SELECT query uses the floor function with the Product_Quantity column of the above Product_Details table:

SELECT Product_Quantity, FLOOR(Product_Quantity) AS floor_Value_of_Product_Quantity FROM Product_Details;

This query shows the floor value of product quantity of each product.

Output:

Product_Quantityfloor_Value_of_Product_Quantity
36.25036
75.50075
68.35068
48.85048
35.90035
20.75020
12.25012