
Answer-first summary for fast verification
Answer:
The question requires calculating percentage rank of products within each region based on sales. Option B uses PERCENT_RANK() OVER(PARTITION BY region ORDER BY sales DESC) which correctly computes the percentage rank (ranging from 0 to 1) for each product within its region, ordered by sales in descending order (higher sales get better rank). The community discussion confirms B is the best choice despite noting that the GROUP BY clause in the option is unnecessary since window functions operate over partitions without aggregation. Other options either use incorrect ranking functions (like RANK() which doesn't produce percentage values) or lack proper partitioning/ordering. The consensus from the discussion, with upvoted comments supporting B and no viable alternatives, reinforces this selection.
Author: LeetQuiz Editorial Team
Ultimate access to all questions.
Given the table sales_table, which contains product sales data across regions, which query will calculate the percentage rank of products within each region based on sales?
The expected output should display the region, product, sales, and the corresponding percentage rank for each product within its region.

A
B
No comments yet.