SQL Functions
SQL has many built-in functions for counting and calculations.
SQL Aggregate Functions
SQL Aggregate functions calculate values from columns 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 sum
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 the specified number of decimal places
- NOW() - Returns the current system date and time
- FORMAT() - Formats the display of a field
Note: In the following sections, we will discuss Aggregate functions and Scalar functions in detail.