MySQL database column Value Comparison and logical function IF Introduction

Source: Internet
Author: User
The column values of the MySQL database are compared, and the actual application proportion of the logical function IF is still the majority. IF you compare the column values of the MySQL database, if you are curious about the actual operations of the logical function IFOracle, the following articles will unveil the mystery of the function. CREATETABLE 'abc' ('uid' int (10) NOT

The column values of the MySQL database are compared, and the actual application proportion of the logical function IF is still the majority. IF you compare the column values of the MySQL database, if you are curious about the actual operations of the logical function IFOracle, the following articles will unveil the mystery of the function. CREATETABLE 'abc' ('uid' int (10) NOT

The column values of the MySQL database are compared, and the actual application proportion of the logical function IF is still the majority. IF you compare the column values of the MySQL database, if you are curious about the actual operations of the logical function IFOracle, the following articles will unveil the mystery of the function.

Abc table in MySQL database

SQL code

 
 
  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


The above content is an introduction to the MySQL database column-Value Comparison logic function IF. 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.