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
- CREATE TABLE `abc` (
- `uid` int(10) NOT NULL,
- `num1` int(8) NOT NULL,
- `num2` int(8) NOT NULL,
- `num3` int(8) NOT NULL,
- PRIMARY KEY (`uid`)
- ) ENGINE=InnoDB DEFAULT CHARSET=gbk
- CREATE TABLE `abc` (
- `uid` int(10) NOT NULL,
- `num1` int(8) NOT NULL,
- `num2` int(8) NOT NULL,
- `num3` int(8) NOT NULL,
- PRIMARY KEY (`uid`)
- ) ENGINE=InnoDB DEFAULT CHARSET=gbk
Task: Compares the data in each column and displays the uid and maximum data columns.
Method:
SQL code
- select if((select if(num1>num2,num1,num2))>num3,(select if(num1>num2,num1,num2)),num3)as num,uid from abc;
- 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
- +-----+-----+
- | num | uid |
- +-----+-----+
- | 3 | 1 |
- | 3 | 2 |
- | 4 | 3 |
- | 5 | 4 |
- | 8 | 5 |
- | 13 | 6 |
- | 56 | 7 |
- +-----+-----+
- 7 rows in set
- +-----+-----+
- | num | uid |
- +-----+-----+
- | 3 | 1 |
- | 3 | 2 |
- | 4 | 3 |
- | 5 | 4 |
- | 8 | 5 |
- | 13 | 6 |
- | 56 | 7 |
- +-----+-----+
- 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.