Ranking Values To Determine Highest Value
I have data that looks as such: +-----+--------+--------+--------+ | ID | score1 | score2 | score3 | +-----+--------+--------+--------+ | 123 | 14 | 561 | 580 | | 123 |
Solution 1:
In Redshift, this might be most easily done using case:
select t.*,
(case greatest(score1, score2, score3)
when score1 then 'score1'
when score2 then 'score2'
when score3 then 'score3'
end) as high_score_name,
greatest(score1, score2, score3) as high_score
from t;
Post a Comment for "Ranking Values To Determine Highest Value"