CEIL
CEIL(x)
Returns the smallest integer that is greater than or equal to the given number – it always rounds up. CEILING() is the same.
Parameters
- x – a number or an expression.
Examples
Examples with the customers, products and orders tables use the sample database from the SQL basics series.
SELECT CEIL(4.1) AS a, CEIL(4.0) AS b, CEIL(-4.9) AS negative;
+---+---+----------+ | a | b | negative | +---+---+----------+ | 5 | 4 | -4 | +---+---+----------+
The number of pages of a product listing with four products per page:
SELECT COUNT(*) AS products_count, CEIL(COUNT(*) / 4) AS pages_of_4 FROM products;
+----------------+------------+ | products_count | pages_of_4 | +----------------+------------+ | 6 | 2 | +----------------+------------+
Things to watch out for
- For negative numbers, “up” means toward zero: CEIL(-4.9) is -4.
- The / division returns a decimal number in MySQL even for integers, so CEIL(7 / 2) is 4 – unlike the integer division DIV.
Related:
FLOOR()
ROUND()
TRUNCATE()