SQL Practice Logo

SQLPractice Online

Arithmetic & Numeric Functions: Functions

Module: SQL Fundamentals

-- Basic arithmetic

SELECT

price,

quantity,

price * quantity AS subtotal,

price * quantity * 1.08 AS total_with_tax

FROM order_items;

-- Rounding

SELECT

ROUND(price, 2) AS rounded_price,

CEIL(price) AS rounded_up,

FLOOR(price) AS rounded_down

FROM products;

-- NULL handling

SELECT

salary,

bonus,

salary + COALESCE(bonus, 0) AS total_comp

FROM employees;

-- Aggregates

SELECT

department,

COUNT(*) AS employee_count,

AVG(salary) AS avg_salary,

SUM(salary) AS total_payroll

FROM employees

GROUP BY department;

Operator precedence: () → * / % → + -

NULL + anything = NULL

Integer division truncates: 5 / 2 = 2 (not 2.5)

Use CAST to DECIMAL for precise division

Aggregate functions ignore NULL values

Precision Hierarchy: DECIMAL > NUMERIC > FLOAT

Core references in this topic include WHERE, =, <, >, <=, >=. Learn what each one does, when to use it, and the execution or engine rules that matter.

WHERE

Filters rows before projection and sorting. It decides which rows continue through the query pipeline.

SELECT ... FROM table WHERE condition;

Most performance issues start with a weak WHERE clause or a missing supporting index.

=

Returns rows where the left and right values are exactly equal.