微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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        

原文地址:https://www.jb51.cc/mysql/433017.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐