有没有办法对记录进行排名?

Is there a way to rank across a record?

我正在尝试对“收藏夹”列基于指定列中的最高值的列进行排名 (?)。

当前数据集如何:

user Tops Bought pants bought
anna 50 12
jon 12 50

& 想做的是这个:

user Tops Bought pants bought favorite item
anna 50 12 tops
jon 12 50 pants

谢谢!

您可以使用 case 表达式:

select t.*,
       (case greatest(tops_bought, pants_bought)
            when tops_bought then 'tops'
            when pans_bought then 'pants'
        end) as favorite_item
from t;