Try a simple if/else statement.
Once you have your query, add a column to it. Then loop
through it and update this column based on that simple if/else
statement. You might have a few else ifs depending on the number of
columns you want to compare, but that just makes it long, not
complicated.