
Answer-first summary for fast verification
Answer:
The question requires calculating the proportion of total order quantity for each sales order represented by each product within that sales order. This means we need to calculate OrderQty divided by the total OrderQty for each SalesOrderID. Option D uses 'SUM(OrderQty) OVER (PARTITION BY SalesOrderID)' which correctly calculates the total quantity per sales order, then divides each product's quantity by this total to get the proportion. The community discussion strongly supports D (86% consensus) with multiple comments noting that B is incorrect because it uses 'ORDER BY' instead of 'PARTITION BY', which would not properly group by SalesOrderID. Using PARTITION BY SalesOrderID ensures the window function calculates the sum separately for each sales order, which is exactly what's needed for this proportional calculation.
Author: LeetQuiz Editorial Team
Ultimate access to all questions.
You have a Fabric warehouse containing a table named SalesOrderDetail. The table has three columns: OrderQty, ProductID, and SalesOrderID. There is one row for each unique combination of SalesOrderID and ProductID.
You need to calculate the proportion of the total order quantity for each sales order that is represented by each product within that sales order.
Which T-SQL statement should you execute?
A
B
No comments yet.