How to Floor Numbers in SQL

If you need to round down a number in your SQL database, use the FLOOR() function. This function takes a single argument, which is the number you want to floor. For example, if you wanted to floor the number 3.14, you would use the following query:

SELECT FLOOR(3.14);

Examples

Let's look at a few examples of how this function can be used. Suppose you have a table called numbers with the following data:

numbers
number
3.14
2.71
4.20


If you wanted to floor all of the numbers in this table, you would use the following query:

SELECT FLOOR(number) FROM numbers;

This query would return the result 3, 2, 4, since the numbers 3.14, 2.71, and 4.20 would all be floored to 3, 2, and 4, respectively.

Additional Info

The FLOOR() function is supported by most major databases, including MySQL, PostgreSQL, and SQL Server. However, the syntax may vary slightly depending on the database you are using. For more information, check out the documentation for your particular database.

Want to build your own LLM Apps with AirOps👇👇