English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
SQL has many built-in functions that allow you to perform calculations on data.
SQL aggregate functions perform calculations on a set of values and return a single value. The following table summarizes some useful aggregate functions:
Function | Description |
---|---|
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 perform operations on string input values and then return a string or numeric value. The following table summarizes some useful string functions:
Function | Description |
---|---|
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. |
Date functions are used to perform operations on date values or execute operations.
The following table summarizes some of the most important MySQL built-in date functions:
Function | Description |
---|---|
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.
The following table summarizes some of the most important SQL Server built-in date functions:
Function | Description |
---|---|
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. |