English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Comprehensive List of SQL Built-in Functions

SQL has many built-in functions that allow you to perform calculations on data.

SQL Aggregate Functions

SQL aggregate functions perform calculations on a set of values and return a single value. The following table summarizes some useful aggregate functions:

FunctionDescription
AVG()Return the average value of values
SUM()Return the sum of values
COUNT()Return the number of rows in the result set
MAX()Return the maximum value
MIN()Return the minimum value

SQL String Functions

SQL string functions perform operations on string input values and then return a string or numeric value. The following table summarizes some useful string functions:

FunctionDescription
CONCAT()Return a string by concatenating two or more string values.
CONCAT_WS()Return a string by concatenating two or more string values using a delimiter.
FORMAT()Return a value formatted in a specified format.
LOWER()Convert a string to lowercase.
UPPER()Convert a string to uppercase.
TRIM()Remove leading and trailing spaces from a string.
REVERSE()Return the reverse order of a string value.
SUBSTRING()Return a substring from a string.

SQL Date Functions

Date functions are used to perform operations on date values or execute operations.

MySQL Date Functions

The following table summarizes some of the most important MySQL built-in date functions:

FunctionDescription
NOW()Return the current date and time.
CURDATE()Return the current date.
CURTIME()Return the current time
DATE()Extract the date part from a date or datetime expression.
DAY()Return the day of the month (0-31)
DAYNAME()Return the name of the day of the week.
MONTH()Return the date after a certain number of days.1-12The month of)。
MONTHNAME()Return the name of the month.
YEAR()Return the year.
DATE_FORMAT()Display date and time values in other formats.
EXTRACT()Extract a part of the date.
DATE_ADD()Add a specified time value (or interval) to a date value.
DATE_SUB()Subtract a specified time value (or interval) from a date value.
DATEDIFF()Return the number of days between two dates

Note:These functions return the date and time of the computer running the database server instance.

SQL Server Date Functions

The following table summarizes some of the most important SQL Server built-in date functions:

FunctionDescription
GETDATE()Return the current date and time.
DATEPART()Return the specified date part of a specified date, for example DATEPART(year,'2016-10-25Return2016).
DAY()Return the day of the month (0-31)
MONTH()Return the month from a specified date (0-12The month starting with
YEAR()Return the year of a specified date.
DATEADD()Add or subtract a specified time interval from a date.
DATEDIFF()Return the date or time between two specified dates.
CONVERT()Display date and time values in other formats.