A friend asked for assistance with the below query (see image for additional clarification):
"We need to generate the sales-rank that is based on the number of items sold, and is calculated by product. In other words for a given product, the year with the most number of items sold will be ranked 1, the year with the next number of items sold will be ranked 2, and so on"
I mailed him the following SQL, however he says that all rows come back with a rank of 1
Select product, year, num_of_items_sold
RANK( ) OVER (PARTITION BY product, year ORDER BY num_of_items_sold) as sales_rank
from prod_sales
Am I missing something? Thanks.