CREATE TABLE exmp_test
(
id int,
v1 int,
v2 int,
v3 int,
v4 int
)
SELECT * FROM exmp_test
id v1 v2 v3 v4
1 2 4 6 7
1 4 77 3 8
I want to add the value of the [id] column to (whichever has least value for v1 ,v2 ,v3 ,v4) for each row.
As an example, for the first row, the [id] value should be add to v1 (because it has the lowest value). For the second row, the [id] value should be add to v3 (because it has the lowest value).
How would I write the SQL to do this?