SQL Functions
SQL has many built-in functions for counting and calculating.
SQL Aggregate Functions
SQL Aggregate functions calculate values taken from a column and return a single value.
Useful Aggregate functions:
- AVG() - Returns the average value
- COUNT() - Returns the number of rows
- FIRST() - Returns the value of the first record
- LAST() - Returns the value of the last record
- MAX() - Returns the maximum value
- MIN() - Returns the minimum value
- SUM() - Returns the total
SQL Scalar Functions
SQL Scalar functions return a single value based on the input value.
Useful Scalar functions:
- UCASE() - Converts a field to uppercase
- LCASE() - Converts a field to lowercase
- MID() - Extracts characters from a text field, used in MySql
- SubString(field, 1, end) - Extracts characters from a text field
- LEN() - Returns the length of a text field
- ROUND() - Rounds a numeric field to a specified number of decimal places
- NOW() - Returns the current system date and time
- FORMAT() - Formats the way a field is displayed
**Tip:** In the following sections, we will explain Aggregate functions and Scalar functions in detail.