mysql – 在行和回显编号和列名中查找最高值

经过几个小时后,我找不到答案.

首先我的桌子

  id | one | two | three | four | five | galname
-------------------------------------------------
  1  |  2  |  5  |   23  |  4   | 5    |  Bob

如何在行中找到最高值并显示colomun名称.

three - 23

最佳答案

 select  id,GREATEST(one,two,three,four,five) value,case GREATEST(one,five)
         when one then 'one'
         when two then 'two'
         when three then 'three'
         when four then 'four'
         when five then 'five' end column_name
 from your_table        

dawei

【声明】:淮南站长网内容转载自互联网,其相关言论仅代表作者个人观点绝非权威,不代表本站立场。如您发现内容存在版权问题,请提交相关链接至邮箱:bqsm@foxmail.com,我们将及时予以处理。