MySQL Greatest function

Source: Internet
Author: User

The first few days of encountering a requirement is to take the maximum value out of the three columns,

Thought for a long time did not think out.

So I checked the next.

MySQL provides both greatest and LEAST with N parameters, and returns the maximum and minimum values, respectively.

The following description GREATEST and LEAST syntax of the function:

Greatest (Value1, value2, ...); LEAST (Value1,value2,...);

Parameters may have mixed data types. The following comparison rules apply to these two functions:

  • If any parameter is NULL, then two functions are returned immediately NULL without any comparison.
  • If you use a function in an int or REAL context, or if all parameters are integer values or REAL values, they are compared as INT and REAL to each.
  • If the argument consists of a number and a string, the function compares them as numbers.
  • If at least one parameter is a non-binary (character) string, the function compares the argument as a non-binary string.
  • In all other cases, the function compares the arguments as a binary string

MySQL Greatest function

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.