FLOOR Function in SQLThe 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 FunctionSyntax1: 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 functionExample 1: This example returns the floor value of the specified number: Output:
Example 2: This example returns the floor value of the specified number: Output:
Example 3: This example returns the floor value of 1.1: Output:
Example 4: This example returns the floor value of all the numbers between 21 and 30: Output:
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:
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:
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:
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:
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:
Next TopicLIMIT Function in SQL |