我的表中有四列,分别是 col1、col2、col3、col4。 我可以通过使用找到最大的值(value)
select greatest(col1,col2,col3,col4) from mytable;
但我需要知道最大值的列名。
最佳答案
与 CASE
:
select
case greatest(col1,col2,col3,col4)
when col1 then 'col1'
when col2 then 'col2'
when col3 then 'col3'
when col4 then 'col4'
else null
end greatestcolumnname
from mytable;
关于sql - postgresql如何使用greatest function获取最大值的列名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56392657/