Skip to content
Advertisement

Getting the primacy function for an emolyee

I have this following query to get the primacy for an employee :

My output is like below :

What I want is to get primacy (primary,secondary, tertiary) to each function like below :

The function having the minimal sumOrder will be the primary function and so on.

Advertisement

Answer

You can use a ROW_NUMBER() ordered by the SUM() result, then a CASE to display your custom string value.

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