Difference between revisions of "SQL Functions"

From AgileApps Support Wiki
imported>Aeric
imported>Aeric
 
(49 intermediate revisions by the same user not shown)
Line 1: Line 1:
These functions can be used in your [[SQL Syntax|SQL]] statements.
These functions can be used in your [[SQL Syntax|SQL]] statements.
 
{{Tip|When returning a function value in a SQL [[SQL Syntax#SELECT Statement|SELECT Statement]]:
:* It's necessary to specify a table to select from.
:* It's generally necessary to include an AS clause, so the value has a handle.
:* It's a good idea to include a LIMIT clause, as well
:: <tt>SELECT CURDATE() <b>AS Date</b> FROM Customer</tt>
::: - returns the current date, under the heading "Date", once for each record in the Customer object.
:: <tt>SELECT CURDATE() <b>AS Date</b> FROM Customer LIMIT 1</tt>
::: - returns the current date, under the heading "Date", one time.}}
__TOC__
{{:Common:SQL Legend}}
===Logical Functions===
===Logical Functions===
:{| border="1" cellpadding="5" cellspacing="1"  
:{| border="1" cellpadding="5" cellspacing="1"  
| '''IF(expr1,expr2,expr3)''' || If expr1 is not zero and not null, return expr2. Otherwise, return expr3.  
| '''IF(''expr1,expr2,expr3'')''' || If ''expr1'' is not zero and not null, return ''expr2''. Otherwise, return ''expr3''.  
|-
|-
| '''IFNULL(expr1,expr2)''' || If expr1 is not NULL, return expr1; Otherwise, return expr2.
| '''IFNULL(''expr1,expr2'')''' || If ''expr1'' is not NULL, return ''expr1''; Otherwise, return ''expr2''.
|}
|}
:''Learn more:''
:: MySQL Control Flow Functions<br>http://dev.mysql.com/doc/refman/{{MySqlVersion}}/en/control-flow-functions.html


===String Functions===
===String Functions===
:{| border="1" cellpadding="5" cellspacing="1"  
:{| border="1" cellpadding="5" cellspacing="1"  
| '''CONCAT(str1,str2,...)''' || Concatenates the strings. Returns the result.
| '''CONCAT(''str1'',''str2'',...)''' || Concatenates the strings. Returns the result.
|-
| '''LENGTH(''str'')''' || Returns the length of the string, in bytes. (A mult-byte character counts as multiple bytes.)
|}
:''Learn more:''
:: MySQL String Functions<br>http://dev.mysql.com/doc/refman/{{MySqlVersion}}/en/string-functions.html
 
===Mathematical Functions===
:{| border="1" cellpadding="5" cellspacing="1"
| '''ROUND(''x'')''' || Round ''x'' up or down to the nearest integer value.
|-
|-
| '''LENGTH(str)''' || Returns the length of the string, in bytes. (A mult-byte character counts as multiple bytes.)
| '''ROUND(''x'', ''d'')''' || Round ''x''to ''d'' decimal places.
|}
|}


===Date Functions===
:''Learn more:'' [http://dev.mysql.com/doc/refman/{{MySqlVersion}}/en/mathematical-functions.html MySQL Mathematical Functions]
 
===Date and Time Functions===
:{| border="1" cellpadding="5" cellspacing="1"
|-
| valign="top"| '''CURDATE()''' || Returns current date as a string or number, depending on current context. String format: <tt>'YYYY-MM-DD'</tt>. Numeric format: <tt>YYYYMMDD</tt>.
|-
| valign="top"|  '''CURTIME()''' || Returns current time as a string or number, depending on current context. String format: <tt>'HH:MM:SS'</tt>. Numeric format: <tt>HHMMSS.uuuuuu</tt>, where <tt>uuuuuu</tt> is the number of microseconds.
|-
| valign="top"| '''<span id="DATE_ADD">DATE_ADD</span>(''date'',<br> &nbsp;&nbsp;INTERVAL&nbsp;''expr''&nbsp;''unit'')'''<br>
<br>
''' DATE_SUB(''date'',<br> &nbsp;&nbsp;INTERVAL ''expr'' ''unit'')'''
| Add ''expr'' units to a time value (or subtract from it).<br>
Where: ''expr'' can be a negative number, and where:
:{| border="1" cellpadding="5" cellspacing="1"  
:{| border="1" cellpadding="5" cellspacing="1"  
| '''DATE_ADD''' ||  
! ''unit'' !! Expression Type !! Expression Format
|-
|MICROSECOND<br>
SECOND<br>
MINUTE<br>
HOUR<br>
DAY<br>
WEEK<br>
MONTH<br>
QUARTER<br>
YEARS
| Number
| An integer specifying the number of units.
|-
| SECOND_MICROSECOND || String || 'SECONDS.MICROSECONDS'
|-
| MINUTE_MICROSECOND || String || 'MINUTES:SECONDS.MICROSECONDS'
|-
| MINUTE_SECOND || String || 'MINUTES:SECONDS'
|-
| HOUR_MICROSECOND || String || 'HOURS:MINUTES:SECONDS.MICROSECONDS'
|-
|-
| '''DATEDIFF''' ||
| HOUR_SECOND || String || 'HOURS:MINUTES:SECONDS'
|-
|-
| '''CURDATE''' ||
| HOUR_MINUTE || String || 'HOURS:MINUTES'
|-
|-
| '''NOW''' ||
| DAY_MICROSECOND || String || 'DAYS HOURS:MINUTES:SECONDS.MICROSECONDS'
|-
|-
| '''CURTIME''' ||
| DAY_SECOND || String || 'DAYS HOURS:MINUTES:SECONDS'
|-
|-
| '''DATE_FORMAT''' ||
| DAY_MINUTE || String || 'DAYS HOURS:MINUTES'
|-
|-
| '''DATE_SUB''' ||
| DAY_HOUR || String || 'DAYS HOURS'
|-
|-
| '''DATE''' ||  
| YEAR_MONTH || String || 'YEARS-MONTHS'
|}
|-
|-
| '''DAYOFMONTH''' ||  
| valign="top"| '''DATE(''expr'')''' || Returns the date from a date/time expression.
|-
|-
| '''DAYNAME''' ||  
| valign="top"| '''<span id="DATE_FORMAT">DATE_FORMAT</span>(''date'', ''format'')''' || Puts the date into the specified format.
{| border="1" cellpadding="5" cellspacing="1"
! Format Specifier !! Description
|-
|-
| '''DAYOFWEEK''' ||  
| %a || Abbreviated weekday name (Sun..Sat)
|-
|-
| '''DAYOFYEAR''' ||  
| %b || Abbreviated month name (Jan..Dec)
|-
|-
| '''EXTRACT''' ||  
| %c || Month, numeric (0..12)
|-
|-
| '''FROM_UNIXTIME''' ||  
| %D || Day of the month with English suffix (0th, 1st, 2nd, 3rd, …)
|-
|-
| '''HOUR''' ||  
| %d || Day of the month, numeric (00..31)
|-
|-
| '''LAST_DAY''' ||  
| %e || Day of the month, numeric (0..31)
|-
|-
| '''MINUTE''' ||  
| %f || Microseconds (000000..999999)
|-
|-
| '''MONTH''' ||  
| %H || Hour (00..23)
|-
|-
| '''MONTHNAME''' ||  
| %h || Hour (01..12)
|-
|-
| '''SEC_TO_TIME''' ||  
| %I || Hour (01..12)
|-
|-
| '''SECOND''' ||  
| %i || Minutes, numeric (00..59)
|-
|-
| '''STR_TO_DATE''' ||  
| %j || Day of year (001..366)
|-
|-
| '''SUBTIME''' ||  
| %k || Hour (0..23)
|-
|-
| '''TIME_TO_SEC''' ||  
| %l || Hour (1..12)
|-
|-
| '''TIME''' ||  
| %M || Month name (January..December)
|-
|-
| '''TIMEDIFF''' ||  
| %m || Month, numeric (00..12)
|-
|-
| '''TO_DAYS''' ||  
| %p || AM or PM
|-
|-
| '''UNIX_TIMESTAMP''' ||  
| %r || Time, 12-hour (hh:mm:ss followed by AM or PM)
|-
|-
| '''YEAR''' ||  
| %S || Seconds (00..59)
|-
| %s || Seconds (00..59)
|-
| %T || Time, 24-hour (hh:mm:ss)
|-
| %U || Week (00..53), where Sunday is the first day of the week
|-
| %u || Week (00..53), where Monday is the first day of the week
|-
| %V || Week (01..53), where Sunday is the first day of the week; used with %X
|-
| %v || Week (01..53), where Monday is the first day of the week; used with %x
|-
| %W || Weekday name (Sunday..Saturday)
|-
| %w || Day of the week (0=Sunday..6=Saturday)
|-
| %X || Year for the week where Sunday is the first day of the week, numeric, four digits; used with %V
|-
| %x || Year for the week, where Monday is the first day of the week, numeric, four digits; used with %v
|-
| %Y || Year, numeric, four digits
|-
| %y || Year, numeric (two digits)
|-
| %% || A literal “%” character
|-
| %x || x, for any “x” not listed above
|}
|-
| valign="top"| '''DATEDIFF(''expr1, expr2'')''' || Returns the number of days between the two date or date/time expressions. (Only the date portions are used.)
|-
| valign="top"| '''DAYNAME(''date'')''' || Returns the name of the weekday for the specified date.
|-
| valign="top"| '''DAYOFMONTH(''date'')''' || Returns the day of the month for the specified date.
|-
| valign="top"| '''DAYOFWEEK(''date'')''' || Returns the weekday index for the specified date (1=Sunday, 7=Saturday).
|-
| valign="top"| '''DAYOFYEAR(''date'')''' || Returns the day of the year for the specified date (1 to 366).
|-
| valign="top"| '''EXTRACT(''unit'' FROM ''date'')''' || Extracts the specified part of the date, using the same unit-specifiers as [[#DATE_ADD|DATE_ADD]].
|-
| valign="top"| '''FROM_UNIXTIME(''unix_timestamp'')'''<br>
'''FROM_UNIXTIME(''unix_timestamp'', ''format'')'''
| Returns a representation of the [[#UNIX_TIMESTAMP|UNIX_TIMESTAMP]] as a string in the form <tt>'YYYY-MM-DD HH:MM:SS'</tt> or as number in the form <tt>YYYYMMDDHHMMSS.uuuuuu</tt>, depending on the context. If ''format'' is specified, the result put into that form, using the same specifiers as the [[#DATE_FORMAT|DATE_FORMAT]] function.
|-
| valign="top"| '''HOUR(''time'')''' || Returns the hour value.
|-
| valign="top"| '''LAST_DAY(''date'')''' || Returns the last day of the month for the specified date.
|-
| valign="top"| '''MINUTE(''time'')''' || Returns the minute value.
|-
| valign="top"| '''MONTH(''date'')''' || Returns the month (1=January, 12=December).
|-
| valign="top"| '''MONTHNAME(''date'')''' || Returns the full name of the month.
|-
| valign="top"| '''NOW()''' || Returns the current date and time as a string in the form <tt>'YYYY-MM-DD HH:MM:SS'</tt> or a number in the form <tt>YYYYMMDDHHMMSS.uuuuuu</tt>, depending on context.
|-
| valign="top"| '''SEC_TO_TIME(''seconds'')''' || Converts the specified number of seconds to a time value.
|-
| valign="top"| '''SECOND(''time'')''' || Returns the seconds from the specified time.
|-
| valign="top"| '''STR_TO_DATE(''str, format'')''' || Returns a date for a given string and the format to interpret it with, where format uses the same specifiers as the [[#DATE_FORMAT|DATE_FORMAT]] function.
|-
| valign="top"| '''SUBTIME(''expr, time'')''' || Returns ''expr1'' (a time or date) minus ''expr2'' (a time), in the same format as ''expr1''.
 
:'''Note:'''<br>In the platform, a time and a date/time are stored the same way, as a Date/Time. To send a time value to this function, use the SQL <tt>TIME()</tt> function to extract the value from such fields.
:For example:
::<tt>SELECT TIMEDIFF(TIME(date_time_fld), TIME(time_fld)) AS elapsed_time</tt>
::: <tt>FROM Customer</tt>
 
|-
| valign="top"| '''TIME(''expr'')''' || Returns the time portion of the date/time expression.
|-
| valign="top"| '''TIME_TO_SEC(''time'')''' || Converts the specified time to seconds.
|-
| valign="top"| '''TIMEDIFF(''expr1, expr2'')''' || Returns ''expr1'' minus ''expr2'' expressed as a time value. (Both ''expr1'' and ''expr2'' must be of the same type: time, or date-and-time.)
 
:'''Note:'''<br>In the platform, a time and a date/time are stored the same way, as a Date/Time. To send a time value to this function, use the SQL <tt>TIME()</tt> function to extract the value from such fields.
:For example:
::<tt>SELECT TIMEDIFF(TIME(date_time_fld), TIME(time_fld)) AS new_date</tt>
::: <tt>FROM Customer</tt>
 
|-
| valign="top"| '''TO_DAYS(''date'')''' || Converts the date to the number of days since year 0.
|-
| valign="top"| '''UNIX_TIMESTAMP()'''<br>
'''UNIX_TIMESTAMP(''expr'')'''
| With no argument, returns a Unix timestamp--an unsigned integer containing the number of seconds since the "zero-date" ('1970-01-01 00:00:00' UTC). If ''expr'' is specified, it is converted to the number of seconds since the zero-date. ''Expr'' can be a string containing a date, date-time, or timestamp; Or it can be a number in the form <tt>YYMMDD</tt> or <tt>YYYYMMDD</tt>.
|-
| valign="top"| '''YEAR(''date'')''' || Returns the year for the specified date, in the range 1000 to 9999, Returns 0 for the “zero date" ('1970-01-01 00:00:00' UTC).
|}         
|}         
:''Learn more:''
:: MySQL Date and Time Functions<br>http://dev.mysql.com/doc/refman/{{MySqlVersion}}/en/date-and-time-functions.html


===Aggregate Functions===
===Aggregate Functions===
:{| border="1" cellpadding="5" cellspacing="1"  
:{| border="1" cellpadding="5" cellspacing="1"  
| '''SUM''' ||  
| '''SUM(''expr'')'''<br>'''SUM(DISTINCT&nbsp;''expr'') || Returns the sum of the values in the expression, or of the distinct values in the expression. Returns NULL if the expression has no values.
|-
|-
| '''AVG''' ||  
| '''AVG(''expr'')'''<br>'''AVG(DISTINCT ''expr'') || Returns the average of the values in the expression, or of the distinct values in the expression. Returns NULL if the expression has no values.
|-
|-
| '''COUNT''' ||  
| '''COUNT(''expr'')''' || Returns a count of the number of non-NULL values of ''expr'' in the rows retrieved by a [[SQL Syntax#SELECT Statement|SELECT statement]] Returns 0 if there were no matching rows.
|-
|-
| '''MAX''' ||  
| '''COUNT(*)''' || Returns a count of rows, whether or not they contain NULL values.
|-
|-
| '''MIN''' ||  
| '''COUNT(DISTINCT<br> &nbsp; ''expr'' [, ''expr'' ...])''' || Returns a count of rows with different non-NULL ''expr'' values.
|-
|-
| '''STD''' ||  
| '''MAX(''expr'')'''<br>'''MAX(DISTINCT&nbsp;''expr'') || Returns the maximum of the values in the expression, or of the distinct values in the expression. Returns NULL if the expression has no values.
|-
|-
| '''VARIANCE''' ||  
| '''MIN(''expr'')'''<br>'''MIN(DISTINCT&nbsp;''expr'') || Returns the maximum of the values in the expression, or of the distinct values in the expression. Returns NULL if the expression has no values.
|-
|-
| '''ROUND''' ||  
| '''STD(''expr'')''' || Returns the standard deviation of ''expr''.
|-
| '''VARIANCE(''expr'')''' || Returns the standard variance of ''expr''.
|}
|}


===Miscellaneous Functions===
:''Learn more:''  
:{| border="1" cellpadding="5" cellspacing="1"
:: MySQL Aggregate Functions<br>http://dev.mysql.com/doc/refman/{{MySqlVersion}}/en/group-by-functions.html
| '''DISTINCT''' ||
|}

Latest revision as of 02:24, 19 March 2014

These functions can be used in your SQL statements.

Thumbsup.gif

Tip: When returning a function value in a SQL SELECT Statement:

  • It's necessary to specify a table to select from.
  • It's generally necessary to include an AS clause, so the value has a handle.
  • It's a good idea to include a LIMIT clause, as well
SELECT CURDATE() AS Date FROM Customer
- returns the current date, under the heading "Date", once for each record in the Customer object.
SELECT CURDATE() AS Date FROM Customer LIMIT 1
- returns the current date, under the heading "Date", one time.
Legend
  • [ x ] - Optional (one or none)
  • [, x ... ] - Optional additional values, in a comma-separated list
  • x | y - Choose one. Curly braces are added when needed: { x | y } ...
  • CAPITALIZED - SQL Keyword (case insensitive)
  • italicized - Value you supply. (Table names and column names are case-sensitive)

Logical Functions

IF(expr1,expr2,expr3) If expr1 is not zero and not null, return expr2. Otherwise, return expr3.
IFNULL(expr1,expr2) If expr1 is not NULL, return expr1; Otherwise, return expr2.
Learn more:
MySQL Control Flow Functions
http://dev.mysql.com/doc/refman/5.5/en/control-flow-functions.html

String Functions

CONCAT(str1,str2,...) Concatenates the strings. Returns the result.
LENGTH(str) Returns the length of the string, in bytes. (A mult-byte character counts as multiple bytes.)
Learn more:
MySQL String Functions
http://dev.mysql.com/doc/refman/5.5/en/string-functions.html

Mathematical Functions

ROUND(x) Round x up or down to the nearest integer value.
ROUND(x, d) Round xto d decimal places.
Learn more: MySQL Mathematical Functions

Date and Time Functions

CURDATE() Returns current date as a string or number, depending on current context. String format: 'YYYY-MM-DD'. Numeric format: YYYYMMDD.
CURTIME() Returns current time as a string or number, depending on current context. String format: 'HH:MM:SS'. Numeric format: HHMMSS.uuuuuu, where uuuuuu is the number of microseconds.
DATE_ADD(date,
  INTERVAL expr unit)


DATE_SUB(date,
  INTERVAL expr unit)

Add expr units to a time value (or subtract from it).

Where: expr can be a negative number, and where:

unit Expression Type Expression Format
MICROSECOND

SECOND
MINUTE
HOUR
DAY
WEEK
MONTH
QUARTER
YEARS

Number An integer specifying the number of units.
SECOND_MICROSECOND String 'SECONDS.MICROSECONDS'
MINUTE_MICROSECOND String 'MINUTES:SECONDS.MICROSECONDS'
MINUTE_SECOND String 'MINUTES:SECONDS'
HOUR_MICROSECOND String 'HOURS:MINUTES:SECONDS.MICROSECONDS'
HOUR_SECOND String 'HOURS:MINUTES:SECONDS'
HOUR_MINUTE String 'HOURS:MINUTES'
DAY_MICROSECOND String 'DAYS HOURS:MINUTES:SECONDS.MICROSECONDS'
DAY_SECOND String 'DAYS HOURS:MINUTES:SECONDS'
DAY_MINUTE String 'DAYS HOURS:MINUTES'
DAY_HOUR String 'DAYS HOURS'
YEAR_MONTH String 'YEARS-MONTHS'
DATE(expr) Returns the date from a date/time expression.
DATE_FORMAT(date, format) Puts the date into the specified format.
Format Specifier Description
%a Abbreviated weekday name (Sun..Sat)
%b Abbreviated month name (Jan..Dec)
%c Month, numeric (0..12)
%D Day of the month with English suffix (0th, 1st, 2nd, 3rd, …)
%d Day of the month, numeric (00..31)
%e Day of the month, numeric (0..31)
%f Microseconds (000000..999999)
%H Hour (00..23)
%h Hour (01..12)
%I Hour (01..12)
%i Minutes, numeric (00..59)
%j Day of year (001..366)
%k Hour (0..23)
%l Hour (1..12)
%M Month name (January..December)
%m Month, numeric (00..12)
%p AM or PM
%r Time, 12-hour (hh:mm:ss followed by AM or PM)
%S Seconds (00..59)
%s Seconds (00..59)
%T Time, 24-hour (hh:mm:ss)
%U Week (00..53), where Sunday is the first day of the week
%u Week (00..53), where Monday is the first day of the week
%V Week (01..53), where Sunday is the first day of the week; used with %X
%v Week (01..53), where Monday is the first day of the week; used with %x
%W Weekday name (Sunday..Saturday)
%w Day of the week (0=Sunday..6=Saturday)
%X Year for the week where Sunday is the first day of the week, numeric, four digits; used with %V
%x Year for the week, where Monday is the first day of the week, numeric, four digits; used with %v
%Y Year, numeric, four digits
%y Year, numeric (two digits)
%% A literal “%” character
%x x, for any “x” not listed above
DATEDIFF(expr1, expr2) Returns the number of days between the two date or date/time expressions. (Only the date portions are used.)
DAYNAME(date) Returns the name of the weekday for the specified date.
DAYOFMONTH(date) Returns the day of the month for the specified date.
DAYOFWEEK(date) Returns the weekday index for the specified date (1=Sunday, 7=Saturday).
DAYOFYEAR(date) Returns the day of the year for the specified date (1 to 366).
EXTRACT(unit FROM date) Extracts the specified part of the date, using the same unit-specifiers as DATE_ADD.
FROM_UNIXTIME(unix_timestamp)

FROM_UNIXTIME(unix_timestamp, format)

Returns a representation of the UNIX_TIMESTAMP as a string in the form 'YYYY-MM-DD HH:MM:SS' or as number in the form YYYYMMDDHHMMSS.uuuuuu, depending on the context. If format is specified, the result put into that form, using the same specifiers as the DATE_FORMAT function.
HOUR(time) Returns the hour value.
LAST_DAY(date) Returns the last day of the month for the specified date.
MINUTE(time) Returns the minute value.
MONTH(date) Returns the month (1=January, 12=December).
MONTHNAME(date) Returns the full name of the month.
NOW() Returns the current date and time as a string in the form 'YYYY-MM-DD HH:MM:SS' or a number in the form YYYYMMDDHHMMSS.uuuuuu, depending on context.
SEC_TO_TIME(seconds) Converts the specified number of seconds to a time value.
SECOND(time) Returns the seconds from the specified time.
STR_TO_DATE(str, format) Returns a date for a given string and the format to interpret it with, where format uses the same specifiers as the DATE_FORMAT function.
SUBTIME(expr, time) Returns expr1 (a time or date) minus expr2 (a time), in the same format as expr1.
Note:
In the platform, a time and a date/time are stored the same way, as a Date/Time. To send a time value to this function, use the SQL TIME() function to extract the value from such fields.
For example:
SELECT TIMEDIFF(TIME(date_time_fld), TIME(time_fld)) AS elapsed_time
FROM Customer
TIME(expr) Returns the time portion of the date/time expression.
TIME_TO_SEC(time) Converts the specified time to seconds.
TIMEDIFF(expr1, expr2) Returns expr1 minus expr2 expressed as a time value. (Both expr1 and expr2 must be of the same type: time, or date-and-time.)
Note:
In the platform, a time and a date/time are stored the same way, as a Date/Time. To send a time value to this function, use the SQL TIME() function to extract the value from such fields.
For example:
SELECT TIMEDIFF(TIME(date_time_fld), TIME(time_fld)) AS new_date
FROM Customer
TO_DAYS(date) Converts the date to the number of days since year 0.
UNIX_TIMESTAMP()

UNIX_TIMESTAMP(expr)

With no argument, returns a Unix timestamp--an unsigned integer containing the number of seconds since the "zero-date" ('1970-01-01 00:00:00' UTC). If expr is specified, it is converted to the number of seconds since the zero-date. Expr can be a string containing a date, date-time, or timestamp; Or it can be a number in the form YYMMDD or YYYYMMDD.
YEAR(date) Returns the year for the specified date, in the range 1000 to 9999, Returns 0 for the “zero date" ('1970-01-01 00:00:00' UTC).
Learn more:
MySQL Date and Time Functions
http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html

Aggregate Functions

SUM(expr)
SUM(DISTINCT expr)
Returns the sum of the values in the expression, or of the distinct values in the expression. Returns NULL if the expression has no values.
AVG(expr)
AVG(DISTINCT expr)
Returns the average of the values in the expression, or of the distinct values in the expression. Returns NULL if the expression has no values.
COUNT(expr) Returns a count of the number of non-NULL values of expr in the rows retrieved by a SELECT statement Returns 0 if there were no matching rows.
COUNT(*) Returns a count of rows, whether or not they contain NULL values.
COUNT(DISTINCT
  expr [, expr ...])
Returns a count of rows with different non-NULL expr values.
MAX(expr)
MAX(DISTINCT expr)
Returns the maximum of the values in the expression, or of the distinct values in the expression. Returns NULL if the expression has no values.
MIN(expr)
MIN(DISTINCT expr)
Returns the maximum of the values in the expression, or of the distinct values in the expression. Returns NULL if the expression has no values.
STD(expr) Returns the standard deviation of expr.
VARIANCE(expr) Returns the standard variance of expr.
Learn more:
MySQL Aggregate Functions
http://dev.mysql.com/doc/refman/5.5/en/group-by-functions.html