あなたが動的に列に影響を与えることができません名ができますが、値を注文することができます。
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、あなたの場合のように)で動作します。
'*選択second_colのdesc' – Bhargav
によってテーブルの順序からこの種の問題は、凶悪なデザイン – Strawberry