💻 Introduction
SQL Mathematical functions allow you to perform numeric calculations easily. Functions like ROUND, CEIL, FLOOR, MOD, and ABS are widely used in reporting, calculations, and data cleaning.
1️⃣ ROUND – Rounding Numbers
The ROUND function rounds a number to a specified number of decimal places.
SELECT ROUND(123.4567, 2) AS RoundedValue;
-- Output → 123.46
2️⃣ CEIL – Smallest Integer Greater Than or Equal
The CEIL (or CEILING) function returns the smallest integer greater than or equal to a number.
SELECT CEIL(123.45) AS CeilValue;
-- Output → 124
3️⃣ FLOOR – Largest Integer Less Than or Equal
The FLOOR function returns the largest integer less than or equal to a number.
SELECT FLOOR(123.95) AS FloorValue;
-- Output → 123
4️⃣ MOD – Remainder After Division
The MOD function returns the remainder of a number divided by another number.
SELECT MOD(10, 3) AS ModValue;
-- Output → 1
5️⃣ ABS – Absolute Value
The ABS function returns the absolute (positive) value of a number.
SELECT ABS(-123.45) AS AbsoluteValue;
-- Output → 123.45
Tip: Use mathematical functions for financial reports, percentages, rounding amounts, and handling numeric comparisons.
✅ Key Takeaways
ROUND→ Round to decimalsCEIL→ Round upFLOOR→ Round downMOD→ Get remainderABS→ Get absolute value
📘 Quick Reference – Common SQL Mathematical Functions
| Function | Description | Example | Result |
|---|---|---|---|
| ROUND(x, d) | Rounds x to d decimal places | ROUND(123.456, 2) |
123.46 |
| CEIL(x) | Smallest integer ≥ x | CEIL(7.2) |
8 |
| FLOOR(x) | Largest integer ≤ x | FLOOR(7.8) |
7 |
| MOD(a, b) | Remainder of a ÷ b | MOD(10, 3) |
1 |
| ABS(x) | Absolute value of x | ABS(-15) |
15 |
📚 Continue Learning
💬 Got a question about SQL Mathematical Functions? Drop it in the comments below and let’s discuss!