WITH t AS ( SELECT 1 id, 3 a, 5 b, 1 c FROM dual UNION ALL SELECT 2, 4, 3, 1 FROM dual ) SELECT id , a, b, c , GREATEST(a, b, c) v_1st , DECODE(GREATEST(a, b, c), a, GREATEST(b, c) , b, GREATEST(a, c) , c, GREATEST(a, b) ) v_2nd_1 , a + b + c - GREATEST(a, b, c) - LEAST(a, b, c) v_2nd_b , LEAST(a, b, c) v_3rd FROM t ;