SQL Functions
Just like any other computer language, SQL supports the use of functions to manipulate with data. Function is a simple operations that are usually performed on data.
SQL has two categories of functions: set (aggregate) functions and scalar functions.
SQL Aggregate Functions
These functions take information from multiple table rows, process that information in some way, and deliver a single row answer.
Useful aggregate functions:
- AVG() – Returns a column’s average value
- COUNT() – Returns the number of rows in a table column
- FIRST() – Returns the first value
- LAST() – Returns the last value
- MAX() – Returns the column’s largest value
- MIN() – Returns the column’s smallest value
- SUM() – Returns the sum of column’s values
The use of these functions is explained in the following sections.
SQL Scalar functions
SQL scalar functions return a single value, based on the input value.
Useful scalar functions:
- UCASE() – Converts a table field to upper case
- LCASE() – Converts a table field to lower case
- MID() – Extract characters from a text field
- LEN() – Returns the length of a text field
- ROUND() – Rounds a numeric field to the number of decimals specified
- NOW() – Returns the current system date and time
- FORMAT() – Formats how a field is to be displayed