FLOOR()

SQL · Math Functions

Theory

FLOOR rounds a number down to the nearest whole number. FLOOR(4.8) is 4, FLOOR(4.2) is 4 and FLOOR(5) stays 5. 'Down' means towards negative infinity, so FLOOR(-4.2) is -5. This differs from simply cutting off the decimals (CAST to integer, or TRUNC), which gives -4 for negatives.

FLOOR is ideal when only complete units count, such as full years of service, completed hours, or whole multiples of a pack size. It is also the classic way to put numbers into equal-width buckets: FLOOR(salary / 10000) * 10000 maps ₹58,000 to the 50,000 band and ₹65,000 to the 60,000 band, which you can then GROUP BY to build a histogram. FLOOR is spelled the same in PostgreSQL, MySQL, SQL Server, Oracle and Snowflake. SQLite provides floor() when math functions are enabled; for positive numbers, CAST(x AS INTEGER) gives the same result.

Why we use it

Many rules count only finished units: completed years, full batches, whole pages filled. FLOOR drops the unfinished part. It is also the simplest way to group continuous values into fixed-size ranges.

When to use it

Use FLOOR for bucketing (salary bands, age groups), completed-unit counts and integer division with decimals. Use CEIL when partial units must be counted as whole, and ROUND for the nearest value.

How it works

  1. Input number, e.g. 58000 / 10000 = 5.8
  2. Is it already a whole number? Yes: Return it unchanged. No: Continue.
  3. Move down to the next integer towards -infinity
  4. Optionally multiply back: 5 * 10000 = 50000 band
  5. Group or label rows by that bucket

Syntax

FLOOR(number)

Example

SELECT FLOOR(4.8);
-- 4

Key points

SQL topics

Introduction to SQL

Querying Data

Sorting Rows

Limiting Rows

Filtering Rows

Joining Multiple Tables

Grouping Rows

SET Operators

Working with Tables

Modifying Data

Views & Triggers

Conditional Expressions

SQL Subqueries

Aggregate Functions

Window Functions

String Functions

Date Functions

Math Functions

Extra Concepts

T
Tech Town
Log InSign Up Free
Home SQL Python DSA Power BI Snowflake Databricks Spark Gen AI Practice Problems Contest Blog

Master SQL from Zero to Pro

All SQL topics in one place. Click any topic in the sidebar — content opens right here without leaving the page.

{{ sectionCount }}
Sections
{{ topicCount }}
Topics
Free
Forever
Hands-on practice Practice SQL Online Solve 150 SQL interview problems in a live editor with instant checking. Start practising →
Section {{ sec.num }}

{{ sec.label }}

SQL  /  {{ current.sectionLabel }}  /  {{ current.name }}

{{ current.name }}

Theory

{{ current.def }}

Why we use it

{{ rich.why }}

When to use it

{{ rich.when }}

Diagram

{{ rich.dg.caption }}

{{ tb.title }}
{{ c.v }}
{{ rich.dg.op }}
➜
{{ rich.dg.output.title }}
{{ c.v }}
{{ nd.label }}
{{ nd.sub }}
{{ nd.label }}
{{ nd.sub }}
{{ rich.dg.left.title }}
{{ it }}
{{ rich.dg.right.title }}
{{ it }}
Flowchart — how it works
{{ nd.text }}
{{ nd.text }}
◇ {{ nd.text }}
Yes → {{ nd.yes }}
No → {{ nd.no }}
Syntax
{{ current.syntax }}
Example
{{ current.example }}
▶ Try It Live — runs against a real sample database
{{ liveError }}
{{ col }}
{{ cell }}
Key Points — click to check off as you learn
  • {{ pt.mark }} {{ pt.text }}

Share this topic