MySQL CEILING Function

MySQL CEILING function is one of the Numeric Functions, which returns the closest integer value that is greater than or equal to the specified expression. The basic syntax of the CEIL or CEILING in MySQL is as shown below:

-- CEILING Function Syntax
SELECT CEILING (Numeric_Expression)
FROM Source

-- CEIL Function Syntax
SELECT CEIL (Numeric_Expression)
FROM Source

To demonstrate the Numeric method, we are going to use the below shown data.

Numeric Functions Source Table 1

MySQL CEILING Function Example

The CEILING function displays the closest integer value and the following query shows multiple ways to use this one.


-- Ceiling Function on Negative Value
SELECT CEILING(-1150.01) AS `Ceiling Value`;

-- on Positive Value
SELECT CEILING(125.07) AS `Ceiling Value`;

-- on string value
SELECT CEILING('712.17') AS `Ceiling Value`;

-- on String
SELECT CEILING('MySQL') AS `Ceiling Value`;

-- on NULLs
SELECT CEILING('NULL') AS `Ceiling Value`;

From the below screenshot, you can see that we used this method on different kinds of values.

MySQL CEILING Function Example 2

MySQL CEIL Function Example

The CEIL function is the synonym for the ceiling Numeric Function. The following query shows you this with examples.

-- Ceil Function on Negative Value
SELECT CEIL(-19.91) AS `Ceil Value`;

-- on Positive Value
SELECT CEIL(25.02) AS `Ceil Value`;

-- on string value
SELECT CEIL('1415.19') AS `Ceil Value`;

From the screenshot below, you can see we used this one on different values.

MySQL CEIL Function Example 3

Example 2

The MySQL CEILING or CEIL also allows you to find the closest value for the column data. In this MySQL example, we are going to find the closet integer values for all the records present in the Service Grade column.


SELECT Product, Color,
		StandardCost, CEILING(StandardCost) AS Cost, 
        Sales, CEILING(Sales) AS Sales, 
        TaxAmt, CEIL(TaxAmt) AS Tax,
        ServiceGrade, CEIL(ServiceGrade) AS Grade
FROM `numeric functions`;
MySQL CEILING Function Example 4

MySQL CEILING WHERE Clause Example

We can also use the MySQL CEIL or CEILING function in Where Clause as well. In this example, we use this in Where Clause to restrict the records selected by the SELECT Statement.

SELECT Product, Color,
		StandardCost, CEILING(StandardCost) AS Cost, 
        Sales, CEILING(Sales) AS Sales, 
        TaxAmt, CEIL(TaxAmt) AS Tax,
        ServiceGrade, CEIL(ServiceGrade) AS Grade
FROM `numeric functions`
WHERE CEILING(StandardCost) > 10000;
MySQL CEILING Function Example 5