您无法动态影响列名称,但您可以对值进行排序:
select
greatest(N1, N2, N3, N4, N5) as col1,
case greatest(N1, N2, N3, N4, N5)
when N1 then greatest(N2, N3, N4, N5)
when N2 then greatest(N1, N3, N4, N5)
when N3 then greatest(N1, N2, N4, N5)
when N4 then greatest(N1, N2, N3, N5)
when N5 then greatest(N1, N2, N3, N4)
end as col2,
case greatest(N1 + N2, N1 + N3, N1 + N4, N1 + N5, N2 + N3, N2 + N4, N2 + N5, N3 + N4, N3 + N5, N4 + N5)
when N1 + N2 then greatest(N3, N4, N5)
when N1 + N3 then greatest(N2, N4, N5)
when N1 + N4 then greatest(N2, N3, N5)
when N1 + N5 then greatest(N2, N3, N4)
when N2 + N3 then greatest(N1, N4, N5)
when N2 + N4 then greatest(N1, N3, N5)
when N2 + N5 then greatest(N1, N3, N4)
when N3 + N4 then greatest(N1, N2, N5)
when N3 + N5 then greatest(N1, N2, N4)
when N4 + N5 then greatest(N1, N2, N3)
end as col3,
case least(N1, N2, N3, N4, N5)
when N1 then least(N2, N3, N4, N5)
when N2 then least(N1, N3, N4, N5)
when N3 then least(N1, N2, N4, N5)
when N4 then least(N1, N2, N3, N5)
when N5 then least(N1, N2, N3, N4)
end as col4,
least(N1, N2, N3, N4, N5) as col5
from table
这将适用于表中任意数量的行(而不是像您的情况那样只有 1 行)。