Database systems are frequently called upon to perform financial auditing, scientific computations, statistical modeling, and percentage calculations. SQL provides built-in Numeric & Math Functions that operate efficiently on integer, float, and decimal data types.
| Function & Syntax | Operation Performed | Example & Output |
|---|---|---|
| ROUND(x, [d]) | Rounds number x to d decimal places (default is 0). |
ROUND(3.856, 2) → 3.86 |
| CEIL(x) / CEILING(x) | Rounds number UP to the nearest whole integer. | CEIL(4.01) → 5 |
| FLOOR(x) | Rounds number DOWN to the nearest whole integer. | FLOOR(4.99) → 4 |
| ABS(x) | Returns the absolute (non-negative) magnitude. | ABS(-25.50) → 25.50 |
| MOD(n, d) | Returns the integer remainder of division (n % d). |
MOD(10, 3) → 1 |
| POWER(x, y) | Computes base x raised to exponent y. |
POWER(2, 8) → 256 |
| SQRT(x) | Returns square root of a non-negative number. | SQRT(81) → 9 |
-- Compute tax, provident fund, and rounded net salary
SELECT
emp_name,
salary,
ROUND(salary * 0.12, 2) AS pf_deduction,
ROUND(salary * 0.10, 2) AS income_tax,
FLOOR(salary - (salary * 0.22)) AS net_take_home
FROM employees;
Next, let us master calendar calculations using SQL Date & Time Functions!
ROUND(x, d) rounds x to d decimal places using standard half-up rounding. CEIL(x) rounds UP to the nearest integer. FLOOR(x) rounds DOWN to the nearest integer.
MOD(n, d) or n % d returns the remainder of dividing n by d (e.g., MOD(17, 5) returns 2). It is frequently used to identify odd/even rows.
ABS(x) returns the absolute positive value of a number (e.g., ABS(-45.8) returns 45.8).
Proceed to the next class in sequence to build production mastery of relational database architecture.
Continue to Class 28: Date & Time Functions → Previous: ← String Functions | Full Syllabus
Combining math functions with SUM, AVG, and STDDEV.
Formatting numbers as currency strings and decimals.
DECIMAL vs FLOAT vs INT precision and rounding nuances.
Calculating day intervals, durations, and timestamps.