Arithmetic & Numeric Functions: Concept
Module: SQL Fundamentals
Arithmetic operators perform calculations on numeric values. Numeric functions transform and analyze numbers. Aggregate functions compute statistics across multiple rows.
**Arithmetic Operators:**
- Addition: +
- Subtraction: -
- Multiplication: *
- Division: / (watch for integer division!)
- Modulo: % (remainder)
**Operator Precedence:**
1. Parentheses ()
2. Multiplication *, Division /, Modulo %
3. Addition +, Subtraction -
**Common Numeric Functions:**
- ROUND(n, d): Round to d decimal places
- CEIL(n): Round up to nearest integer
- FLOOR(n): Round down to nearest integer
- ABS(n): Absolute value
- POWER(n, p): n raised to power p
- SQRT(n): Square root
**NULL Handling:**
- NULL + anything = NULL
- Use COALESCE(value, 0) to replace NULL with default
**Performance Impact:**
- Functions on indexed columns break indexes → full scan
- Example: WHERE ROUND(salary) = 50000 → 100x slower
- Better: WHERE salary BETWEEN 49500 AND 50500
Essential for data analysts, BI developers, and backend engineers. Understanding numeric precision (DECIMAL vs FLOAT) prevents financial errors. Aggregate functions are the foundation of reporting and analytics. Math functions in WHERE clauses break indexes causing 100x slowdowns.
Numeric calculations power every business application - pricing with tax, discounts, commissions, financial reports, statistical analysis. Used in invoices, dashboards, analytics, and data transformations. DECIMAL precision prevents $0.01 discrepancies in financial systems.