
You are given two tables:
products
product_id
(int, primary key)
category
(string)
order_items
order_id
(int)
product_id
(int)
quantity
(int)
unit_price
(decimal)
created_at
(timestamp)
Task
quantity * unit_price
.
category
, return the
top 3 products by total revenue
in 2024.
product_id
first.
Output Return rows with:
category
product_id
total_revenue
rank_in_category
(1 = highest revenue within the category)
Sort the final output by category, then rank_in_category, then product_id.
Notes/Constraints
ROW_NUMBER
,
RANK
, or
DENSE_RANK
).