一行数据中三列值的比较
原表hxy

处理后的表

处理此需求,可用三种方法
方法一:
select key,case when z> case when x>y then x else y end then z else case when x>y then x else y end end col from hxy;
方法二:
select key,max(col) from (select key,x as col from hxy union all select key,y as col from hxy union all select key,z as col from hxy) ;
方法三:此方式使用oracle中的内置函数处理
select key,greatest(greatest(x,y),z) col from hxy;
-----备注:greatest函数在处理含有null值的数值时,返回值为null,且MySQL中此函数亦适用

浙公网安备 33010602011771号