Built-in functions transform or summarize values without you writing any procedural logic. This lesson covers the ones you'll reach for constantly.
Counts the number of rows.
SELECT COUNT(*) FROM table_name;SELECT COUNT(*) FROM Employee;* or a specific column — COUNT(column) skips NULLs in that column, COUNT(*) doesn't.Common Mistake
Using COUNT(column) expecting it to count NULLs — it doesn't.
Adds up all values in a numeric column.
SELECT SUM(column) FROM table_name;SELECT SUM(salary) FROM Employee;Common Mistake
Applying SUM to a non-numeric column.
Returns the mean of a numeric column.
SELECT AVG(column) FROM table_name;SELECT AVG(salary) FROM Employee;Common Mistake
Forgetting AVG ignores NULLs, which can skew results versus a manual calculation done elsewhere.
Returns the smallest or largest value in a column.
SELECT MIN(column), MAX(column) FROM table_name;SELECT MIN(salary), MAX(salary) FROM Employee;Common Mistake
Calling MIN/MAX per row in application code instead of letting the engine aggregate it in one pass.
Manipulate text values — casing, joining, trimming, extracting.
UPPER(col) · LOWER(col) · CONCAT(a,b) · SUBSTRING(col,start,len) · TRIM(col) · LENGTH(col)SELECT UPPER(name), CONCAT(name, ' - ', department)
FROM Employee;Common Mistake
Comparing strings without normalizing case first, missing matches that a human would consider identical.
Work with dates and times — current date, differences, arithmetic.
NOW() · CURDATE() · DATEDIFF(a,b) · DATE_ADD(date, INTERVAL n unit)SELECT DATEDIFF(NOW(), hire_date) AS days_employed
FROM Employee;Common Mistake
Comparing DATE and DATETIME columns directly without matching precision first.
Perform math on numeric values directly in a query.
ROUND(col, n) · ABS(col) · MOD(a, b)SELECT ROUND(salary / 12, 2) AS monthly_pay
FROM Employee;Common Mistake
Rounding in application code instead of the query, causing display mismatches between the two.
Functions handle the everyday math and text work. The next lesson covers window functions — a related but more powerful tool for calculating across a set of rows without collapsing them into one.