Practice Exam

Question 69 of 75

Complete SQL Query For Hierarchical Summaries

You work as a Business Intelligence Developer for Mark at MDFT Pro, a well-known training agency. MDFT Pro operates a Fabric workspace that contains a warehouse named DW1, which stores sales data for training courses and educational materials. The warehouse contains a SalesOrderDetail table tracking order quantities with product IDs and modification dates, and a Product table with product names. Mark has asked you to create a report that presents summarized values of all order quantities by year and product. The business requirement specifies that the results must include not only the detailed year-product combinations but also a summary of the order quantities at the year level for all products combined, allowing stakeholders to see both granular and aggregated sales patterns.

The warehouse contains the following structure:

Table NameColumn NameDescription
SalesOrderDetailProductIDThe ID of the ordered product
SalesOrderDetailModifiedDateThe date of the order
SalesOrderDetailOrderQtyThe number of products ordered
ProductProductIDThe unique ID of a product
ProductNameThe name of a product

How should you complete the code?

SELECT
    YEAR(ModifiedDate) AS OrderDate,
    p.Name AS ProductName,
    SUM(so.OrderQty) AS OrderQty
FROM
    dbo.SalesOrderDetail so
    INNER JOIN dbo.Product p ON p.ProductID = so.ProductID
GROUP BY
    ____________________

Choose the correct answer from the options below.

Explanations for each answer:

Learn more about SQL GROUP BY CUBE and ROLLUP:
SQL GROUP BY Operations
Next Question
Discuss this question on social media: