ceil
The ceil() function returns the nearest positive or negative integer value greater than or equal to the provided decimal input number.
Syntax
The syntax of the ceil() function is:
CEIL(x)
The ceil() function requires one argument:
-
x: A positive or a negative decimal number (or an expression that evaluates to a decimal number).
Examples
Round up a positive decimal value
This example demonstrates how the ceil() function rounds up a positive decimal value:
SELECT CEIL (300.55);
This returns 301, as it is the nearest integer value greater than 300.55.
+------+
| f |
+------+
| 301 |
+------+
Round up a negative decimal value
This example demonstrates how the ceil() function rounds up a negative decimal value:
SELECT CEIL(-89.9) AS "Ceil";
The output of this statement is -89, as -89 is the nearest integer value greater than or equal to -89.9.
+-------+
| Ceil |
+-------+
| -89 |
+-------+
Use the ceil() function with a table
This example demonstrates how to use the ceil() function with a table to round up values in a specific column:
-
First, create a table called CeilRecords:
CREATE TABLE CeilRecords (numbers float); INSERT INTO CeilRecords(numbers) VALUES (-28.85), (-9.4), (0.87), (78.16), (42.16);This statement creates a table called “CeilRecords” with a column called “numbers” and insert 5 decimal values into it.
-
Retrieve and round up the value for all records in the numbers column:
SELECT *, CEIL(numbers) AS CeilValue FROM CeilRecords;The final result will contain:
-
A numbers column with initial decimal values.
-
A CeilValue column with rounded-up integer values.
+---------+------------+ | numbers | CeilValue | +---------+------------+ | -28.85 | -28 | | -9.4 | -9 | | 0.87 | 1 | | 78.16 | 79 | | 42.16 | 43 | +---------+------------+
-