MYSQL queries the maximum value among the three columns

Source: Internet
Author: User
For example, the data structure of mysql is as follows: query the maximum value in the three columns of ABC. Currently, there is an SQL statement that can be implemented. Would you like to ask if there are other better idea statements .. {code ...} in the afternoon, I learned another greatest function {code ...}

Example: The mysql Data structure is as follows:

Query the maximum value in column a B c. Currently, there is an SQL statement that can be implemented. Would you like to know if there are other better idea statements ..

select id,a,b,c,(a+((b+c+abs(b-c))/2)+abs(a-(b+c+abs(b-c))/2))/2 from test; 

I learned another one from others in the afternoon.greatestFunction

select id,a,b,c,greatest(a,b,c) as max from XXX

Reply content:

Example: The mysql Data structure is as follows:

Query the maximum value in column a B c. Currently, there is an SQL statement that can be implemented. Would you like to know if there are other better idea statements ..

select id,a,b,c,(a+((b+c+abs(b-c))/2)+abs(a-(b+c+abs(b-c))/2))/2 from test; 

I learned another one from others in the afternoon.greatestFunction

select id,a,b,c,greatest(a,b,c) as max from XXX

mysql> set @a = 5, @b = 6, @c = 11;Query OK, 0 rows affected (0.00 sec)mysql> select if(@a > @b, if(@a > @c, @a, @c), if(@b > @c, @b, @c)) max;+------+| max  |+------+|   11 |+------+1 row in set (0.00 sec)

select greatest(a,b,c) max from table_name

... Can the program be processed?

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.