MySQL FLOOR Function

MySQL FLOOR function is one of the Numeric Functions, which returns the closest integer value that is less than or equal to the specified expression. The syntax of the MySQL FLOOR function is as shown below:

SELECT FLOOR (Numeric_Expression)
FROM Source

To demonstrate this Numeric function, we are going to use the below shown data

Numeric Functions Source Table 1

MySQL FLOOR Function Example

The MySQL FLOOR returns the closest integer value less than the specified number, and the following query shows multiple ways to use this.

-- Floor Function on Negative Value
SELECT FLOOR(-120.91) AS `Floor Value`;

-- on Positive Value
SELECT FLOOR(205.97) AS `Floor Value`;

-- on the string value
SELECT FLOOR('801.95') AS `Floor Value`;

-- on String
SELECT FLOOR('MySQL') AS `Floor Value`;

-- on NULLs
SELECT FLOOR('NULL') AS `Floor Value`;

From the below screenshot, you can see that we used this method on different values.

MySQL FLOOR Function Example 2

Column Example

The FLOOR Numeric Function also allows you to find the closest value for the column data. In this example, we are going to find the values for all the records present in the Service Grade column.

SELECT Product, Color,
		StandardCost, FLOOR(StandardCost) AS Cost, 
        Sales, FLOOR(Sales) AS Sales, 
        TaxAmt, FLOOR(TaxAmt) AS Tax,
        ServiceGrade, FLOOR(ServiceGrade) AS Grade
FROM `numeric functions`;
MySQL FLOOR Function Example 3

MySQL FLOOR WHERE Clause Example

In MySQL, we can also use this Numeric method in Where Clause as well. In this example, we use this method in the where clause to restrict the records selected by the SELECT Statement.

SELECT Product, Color,
		StandardCost, FLOOR(StandardCost) AS Cost, 
        Sales, FLOOR(Sales) AS Sales, 
        TaxAmt, FLOOR(TaxAmt) AS Tax,
        ServiceGrade, FLOOR(ServiceGrade) AS Grade
FROM `numeric functions`
WHERE FLOOR(TaxAmt) > 200;
MySQL FLOOR Function Example 4