SQL FLOOR()
Published May 26, 2023
Contribute to Docs
The SQL math function FLOOR() returns the largest integer that is less than or equal to a specified numeric value. It effectively rounds down a number to the nearest whole integer.
Syntax
SELECT FLOOR(number)FROM table_name;
number- The value which will be floored / rounded down.
Example
In this example, the following data is given, in a table named employees:
| employee_id | salary |
|---|---|
| 1 | 3500.27 |
| 2 | 1530.90 |
| 3 | 3025.10 |
| 4 | 5040.50 |
The FLOOR() function can be used to return the largest integer that is less than or equal to a given value:
SELECT employee_id, FLOOR(salary) AS floored_salaryFROM employees;
In this SQL statement, the salary values are floored for each employee to get the floored_salary. The AS keyword is used to name the resulting column floored_salary in the output.
The output will be:
| employee_id | floored_salary |
|---|---|
| 1 | 3500 |
| 2 | 1530 |
| 3 | 3025 |
| 4 | 5040 |
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn SQL on Codecademy
- Learn to analyze data with SQL and prepare for technical interviews.
- Includes 9 Courses
- With Certificate
- Beginner Friendly.18 hours
- In this SQL course, you'll learn how to manage large datasets and analyze real data using the standard data management language.
- Beginner Friendly.5 hours