Skip to content
Advertisement

Select column names based on max value by row

I need select column name based on max value by row. I have snowflake database table:

Where is IDs and many categories with counts. I need new column, with category name, where count is max.

Output:

I try window functions… without success.

Advertisement

Answer

You can use the function GREATEST() in a CASE expression:

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement