MySQL Functions

MySQL Functions

This section gives you the most commonly used MySQL functions including aggregate functions, string functions, date time functions, control flow functions, etc.

MySQL aggregate functions

  • MySQL aggregate function - provides a brief overview of the most commonly used MySQL aggregate functions
  • AVG - calculates the average value of a set of values or an expression.
  • COUNT - count the number rows in a table.
  • SUM - calculates the sum of a set of values or an expression.
  • MIN - finds the minimum value in a set of values
  • MAX - finds the maximum value in a set of values
  • GROUP_CONCAT – concatenates strings from a group into a string with various options such as DISTINCTORDER BY and SEPARATOR.
  • MySQL standard deviation functions – shows you how to compute population standard deviation and sample standard deviation by using functions: STDSTDDEV,STDDEV_POP and STDDEV_SAMP. In addition, the population variance and sample variance functions such as VAR_POPVARIANCE and VAR_SAMP are also covered.

MySQL string functions

  • CONCAT - combines two or more strings into one string.
  • LENGTH and CHAR_LENGTH - get the length of strings in bytes and in characters.
  • REPLACE - searches and replaces a substring in a string.
  • SUBSTRING -  extracts a substring starting from a position with a specific length.

MySQL control flow functions

  • IF - returns a value based on a given condition
  • IFNULL - returns the first argument if it is not NULL, otherwise returns the second argument.
  • NULLIF - returns NULL if the first argument is equal to the second argument, otherwise returns the first argument.

MySQL date and time functions

  • DATEDIFF - calculates the number of days between two DATE or DATETIME values.
  • DATE_FORMAT – formats a date value based on a specified date format.
  • STR_TO_DATE - converts a string into a date and time value based on a specified format.
  • NOW - returns the current date and time at which the statement executed.

Other MySQL functions

  • LAST_INSERT_ID - obtains the last generated sequence number of the last inserted record.
  • CAST – converts a value of any type into a value with a specified type.

Share this:

Post a Comment

Thank You

Previous Post Next Post