NumbersSQL standard

CEIL

Rounds a number up — to the nearest integer that isn't smaller than it.

Syntax

CEIL(<number>)
CEILING(<number>)

Any fractional part lifts the number to the next integer: 4.1 becomes 5. An integer stays as it is. CEILING is the same thing with a longer name. Most often it's used to count how many pages, boxes or payments you need.

Data for the examples

orders

idcreated_atamount
12026-07-03 10:15:00120.50
22026-07-28 18:40:0080.25
32026-08-09 09:05:00199.99
42026-08-21 14:30:0045.00
52026-09-02 11:00:0064.75

These tables already exist in the sandbox — the examples below use them. Want to try this in your own database? Copy the SQL.

Up to an integer
SELECT CEIL(4.1) AS up,
CEIL(4.0) AS whole,
CEIL(-4.1) AS negative;
upwholenegative
54-4
How many pages at 2 orders per page
SELECT COUNT(*) AS order_count,
CEIL(COUNT(*) / 2.0) AS pages
FROM orders;
order_countpages
53

We divide by 2.0, not 2 — the reason is explained under “Watch out”.

Watch out

Integer division drops the fractional part before CEIL even runs: CEIL(5 / 2) gives 2, because 5 / 2 is already 2. Make one of the numbers fractional: CEIL(5 / 2.0) gives 3.

For negative numbers, “up” means closer to zero: CEIL(-4.1) gives -4, not -5.

Related functions

Learn more in the course