具有列名称的多个列的最大价值? [英] Greatest value of multiple columns with column name?
本文介绍了具有列名称的多个列的最大价值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我探讨了许多有关如何从多个列中返回最大值以及列名的问题和答案.但是我还没有解决问题 这个问题在这里将解释:
I have explored many questions and answers regarding how to return the greatest values from multiple columns along with column name. But I have not solved the problem here in this question will explain:
但是我不知道如何找出具有最大价值的列名称?有什么想法吗?
But I don't know how to figure out the column name having greatest value? Any ideas?
推荐答案
You can use GREATEST function to find the maximum value among all columns:
SELECT @var_max_val:= GREATEST(col1, col2, col3, ...) AS max_value,
CASE @var_max_val WHEN col1 THEN 'col1'
WHEN col2 THEN 'col2'
...
END AS max_value_column_name
FROM table_name
WHERE ...
这篇关于具有列名称的多个列的最大价值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文