#1 Data Analytics Program in India
₹2,499₹1,499Enroll Now
Step 11
6 min read

Numeric Functions

Learn math functions - round numbers, absolute values, and more!

What are Numeric Functions?

Numeric Function Examples
FunctionInputOutputUse Case
ROUND(19.987, 2)19.98719.99Clean prices
ABS(-50)-5050Distance
FLOOR(19.99)19.9919Round down
CEILING(19.01)19.0120Round up
MOD(21, 2)211Even/Odd check
5 rows

Numeric functions help you do math with numbers - round, absolute value, floor, ceiling, etc.

Simple analogy: Like a calculator built into SQL.

Common Numeric Functions

Numeric Function Examples
FunctionInputOutputUse Case
ROUND(19.987, 2)19.98719.99Clean prices
ABS(-50)-5050Distance
FLOOR(19.99)19.9919Round down
CEILING(19.01)19.0120Round up
MOD(21, 2)211Even/Odd check
5 rows

ROUND - Round Numbers

SELECT ROUND(price, 2) FROM products;

Example:

  • Input: 19.9876
  • Output: 19.99

ABS - Absolute Value (Remove Negative)

SELECT ABS(balance) FROM accounts;

Example:

  • Input: -50
  • Output: 50

FLOOR - Round Down

SELECT FLOOR(price) FROM products;

Example:

  • Input: 19.99
  • Output: 19

CEILING - Round Up

SELECT CEILING(price) FROM products;

Example:

  • Input: 19.01
  • Output: 20

MOD - Remainder After Division

SELECT MOD(age, 2) FROM students;

Example:

  • Input: 21
  • Output: 1 (21 divided by 2 = 10 remainder 1)

Real Examples

Numeric Function Examples
FunctionInputOutputUse Case
ROUND(19.987, 2)19.98719.99Clean prices
ABS(-50)-5050Distance
FLOOR(19.99)19.9919Round down
CEILING(19.01)19.0120Round up
MOD(21, 2)211Even/Odd check
5 rows

Example 1: Round Prices

SELECT product_name, price, ROUND(price, 2) AS rounded_price FROM products;

Example 2: Find Even/Odd Ages

SELECT name, age, CASE WHEN MOD(age, 2) = 0 THEN 'Even' ELSE 'Odd' END AS age_type FROM students;

Example 3: Calculate Tax

SELECT price, ROUND(price * 0.1, 2) AS tax, ROUND(price * 1.1, 2) AS total_with_tax FROM products;

Summary

Numeric Function Examples
FunctionInputOutputUse Case
ROUND(19.987, 2)19.98719.99Clean prices
ABS(-50)-5050Distance
FLOOR(19.99)19.9919Round down
CEILING(19.01)19.0120Round up
MOD(21, 2)211Even/Odd check
5 rows

Common functions:

  • ROUND: Round to decimals
  • ABS: Remove negative sign
  • FLOOR: Round down
  • CEILING: Round up
  • MOD: Get remainder

Finished this topic?

Mark it complete to track your progress and maintain your streak!