Ara*_*aja 2 sql postgresql case
我的表中有四列,分别是 col1、col2、col3、col4。我可以通过使用找到最大的价值
select greatest(col1,col2,col3,col4) from mytable;
Run Code Online (Sandbox Code Playgroud)
但我需要知道最大值的列名。
和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;
Run Code Online (Sandbox Code Playgroud)