Window Functions for Deterministic Ranking
Window functions perform calculations across a set of table rows that are related to the current row. Unlike aggregate functions, they do not group rows into a single output row, preserving the original data detail.
SELECTproduct_id,category,price,ROW_NUMBER() OVER (PARTITION BY category ORDER BY price DESC) as rank_in_categoryFROM products;