Rumah > Artikel > pangkalan data > MySQL数据库列值比较与逻辑函数IF简介
MySQL数据库列值比较 ,以及逻辑函数IF在实际中的应用比例还是占为多数的,如果你对这MySQL数据库列值比较 ,以及逻辑函数IFOracle 实际操作心存好奇的话,以下的文章将会揭开它的神秘面纱。 MySQL数据库里abc 表 Sql代码 CREATETABLE`abc`( `uid`int(10)NOT
MySQL数据库列值比较 ,以及逻辑函数IF在实际中的应用比例还是占为多数的,如果你对这MySQL数据库列值比较 ,以及逻辑函数IFOracle 实际操作心存好奇的话,以下的文章将会揭开它的神秘面纱。
MySQL数据库里abc 表
Sql代码
<ol class="dp-xml"> <li class="alt"><span><span>CREATE TABLE `abc` ( </span></span></li> <li><span>`uid` int(10) NOT NULL, </span></li> <li class="alt"><span>`num1` int(8) NOT NULL, </span></li> <li><span>`num2` int(8) NOT NULL, </span></li> <li class="alt"><span>`num3` int(8) NOT NULL, </span></li> <li><span>PRIMARY KEY (`uid`) </span></li> <li class="alt"> <span>) </span><span class="attribute">ENGINE</span><span>=</span><span class="attribute-value">InnoDB</span><span> DEFAULT </span><span class="attribute">CHARSET</span><span>=</span><span class="attribute-value">gbk</span><span> </span> </li> <li><span>CREATE TABLE `abc` ( </span></li> <li class="alt"><span>`uid` int(10) NOT NULL, </span></li> <li><span>`num1` int(8) NOT NULL, </span></li> <li class="alt"><span>`num2` int(8) NOT NULL, </span></li> <li><span>`num3` int(8) NOT NULL, </span></li> <li class="alt"><span>PRIMARY KEY (`uid`) </span></li> <li> <span>) </span><span class="attribute">ENGINE</span><span>=</span><span class="attribute-value">InnoDB</span><span> DEFAULT </span><span class="attribute">CHARSET</span><span>=</span><span class="attribute-value">gbk</span><span> </span> </li> </ol>
任务:是完成每列数据的比较,将uid 以及最大数据列显示出来。
方法:
Sql代码
<ol class="dp-xml"> <li class="alt"><span><span>select if((select if(num1</span><span class="tag">></span><span>num2,num1,num2))</span><span class="tag">></span><span>num3,(select if(num1</span><span class="tag">></span><span>num2,num1,num2)),num3)as num,uid from abc; </span></span></li> <li> <span>select if((select if(num1</span><span class="tag">></span><span>num2,num1,num2))</span><span class="tag">></span><span>num3,(select if(num1</span><span class="tag">></span><span>num2,num1,num2)),num3)as num,uid from abc; </span> </li> </ol>
这样写感觉不好,有没好的方法来比较。
结果如下:
Java代码
<ol class="dp-xml"> <li class="alt"><span><span>+-----+-----+ </span></span></li> <li><span>| num | uid | </span></li> <li class="alt"><span>+-----+-----+ </span></li> <li><span>| 3 | 1 | </span></li> <li class="alt"><span>| 3 | 2 | </span></li> <li><span>| 4 | 3 | </span></li> <li class="alt"><span>| 5 | 4 | </span></li> <li><span>| 8 | 5 | </span></li> <li class="alt"><span>| 13 | 6 | </span></li> <li><span>| 56 | 7 | </span></li> <li class="alt"><span>+-----+-----+ </span></li> <li><span>7 rows in set </span></li> </ol><br><br>
以上的相关内容就是对MySQL数据库列值比较 逻辑函数IF的介绍,望你能有所收获。