How to use rank in update stmt

Database
Enthusiast

How to use rank in update stmt

Hi,

I have a requirement where I need to populate different fields that would hold individual ranks for different products/categories.
I didn't want to use different update stmts for it rather wanted to do it thru a single update stmt.

Below is an example of how the data is actually :

Country sales ipods_sold iphone_sold sales_rank ipod_rank iphone_rank
US 2000 30 20 1 3 4
US 1500 50 25 2 1 3
.
.
and so on....
Please note that no of rank fields is actually around 20 and didn't want to use 20 update stmts! :(

Please help me if you think there can be a much better/ different approach.
1 REPLY
Senior Apprentice

Re: How to use rank in update stmt

Use an
UPDATE ... FROM (your select to calculate the ranks)

Dieter