QuestionQ136

Prepare data

You have a Fabric warehouse containing a table named SalesOrderDetail. SalesOrderDetail has three columns named OrderQty, ProductID, and SalesOrderlD. SalesOrderDetail has one row for every combination of SalesOrderlD and ProductID.

You need to calculate the proportion of each sales order’s total quantity that each product represents within that sales order.

Which T-SQL statement should you run?

  • A
  • B
  • C
  • D
Explanation

SUM(OrderQty) OVER (PARTITION BY SalesOrderID) calculates the total quantity separately for each sales order, and no ORDER BY means the window includes every row in that order. Dividing each product row’s OrderQty by that per-order total and multiplying by 100 returns its percentage of the sales order.

Learn more

Community Discussion

No comments yet. Be the first to start the discussion!