Introduction to logical functions of MySQL column Value Comparison

Source: Internet
Author: User

This article mainly introduces the practical application of the logical function IF for MySQL column Value Comparison and the SQL code to be used in actual operations, A few days ago, I found a document on the practical application of the logic function IF for MySQL column Value Comparison on a website with good reputation for sharing.

Conversion from Arabic numerals to Chinese numerals in Java

Computer teachers in China are boring.

How to evaluate expressions, such as eval in Javascript

Recommendation circle: Database circle

More abc tables in related recommendation Databases

Logical function IF SQL code for MySQL column Value Comparison

 
 
  1. CREATE TABLE `abc` (   
  2. `uid` int(10) NOT NULL,   
  3. `num1` int(8) NOT NULL,   
  4. `num2` int(8) NOT NULL,   
  5. `num3` int(8) NOT NULL,   
  6. PRIMARY KEY (`uid`)   
  7. ) ENGINE=InnoDB DEFAULT CHARSET=gbk   
  8. CREATE TABLE `abc` (  
  9. `uid` int(10) NOT NULL,  
  10. `num1` int(8) NOT NULL,  
  11. `num2` int(8) NOT NULL,  
  12. `num3` int(8) NOT NULL,  
  13. PRIMARY KEY (`uid`)  
  14. ) ENGINE=InnoDB DEFAULT CHARSET=gbk   

Task: Compares the data in each column and displays the uid and maximum data columns.

Method:

SQL code

 
 
  1. select if((select if(num1>num2,num1,num2))>num3,(select if(num1>num2,num1,num2)),num3)as num,uid from abc;   
  2. select if((select if(num1>num2,num1,num2))>num3,(select if(num1>num2,num1,num2)),num3)as num,uid from abc;   

In this way, the writing is not good, and there are no good methods for comparison.

The result is as follows:

Java code
 

 
 
  1. +-----+-----+   
  2. | num | uid |   
  3. +-----+-----+   
  4. | 3 | 1 |   
  5. | 3 | 2 |   
  6. | 4 | 3 |   
  7. | 5 | 4 |   
  8. | 8 | 5 |   
  9. | 13 | 6 |   
  10. | 56 | 7 |   
  11. +-----+-----+   
  12. 7 rows in set   
  13. +-----+-----+  
  14. | num | uid |  
  15. +-----+-----+  
  16. | 3 | 1 |  
  17. | 3 | 2 |  
  18. | 4 | 3 |  
  19. | 5 | 4 |  
  20. | 8 | 5 |  
  21. | 13 | 6 |  
  22. | 56 | 7 |  
  23. +-----+-----+  
  24. 7 rows in set   

The above content is an introduction to the logic function IF for MySQL column Value Comparison. I hope you will get something.

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.