Skip to content
Advertisement

rank with the sum

Below is the table:

where I want to rank the category based on weightage desc, expected results:

what was already tried: select desnse_rank() over (partition by category order by weightage desc), but I need to rank it based on sum(weightage) per category.

Advertisement

Answer

With a CTE you can do the calculations one by one. First calculate the dense rank for sum per category (ranked_by_sum), then join back to the original table to get the dense rank value for the individual rows:

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