SQL:确定哪一列在每行中具有最大值

MsL*_*Lis 6 sql

我有一个表ID列,A,B,C,D,E ...(总共10个数字列)

对于每一行,我需要找到哪个列具有最大值,以及该值是什么.

EG这是我桌子的一排:
ID A B C D E F G H I J
XY 5 4 9 5 0 1 3 2 1 7

我想生成2个新列:
maxvalue,等于9,maxcol,等于"C"

除了大规模的IF声明之外还有什么建议?

Pre*_*gha 1

我手边没有 sql 处理器,但有类似的东西

select id , colName
from 
(select id, 'A' as colName, a as value union all
select id, 'B' as colName, b as value union all
select id, 'C' as colName, c as value union all
select id, 'D' as colName, d as value union all
select id, 'E' as colName, e as value union all
select id, 'F' as colName, f as value union all
select id, 'G' as colName, g as value union all
select id, 'H' as colName, h as value union all
select id, 'I' as colName, i as value union all
select id, 'J' as colName, j as value)
group by id having max(value)
Run Code Online (Sandbox Code Playgroud)