Exam Preparation Quiz

Question 32 of 75

Choose correct WHERE clause to filter the groups

You work for MDFT Pro, where you’re analyzing course purchase data using a Power BI semantic model backed by a Fabric warehouse named DW1. The warehouse contains the following tables and columns that store course purchases:

Table nameColumn name
PurchaseCourseID
PurchaseModifiedDate
PurchaseOrderQty
CourseCourseID
CourseName

You’ve written the following T-SQL query to summarize OrderQty by year and course, including yearly totals and a grand total:

SELECT 
    YEAR(p.ModifiedDate) AS OrderDate,
    c.Name AS CourseName,
    SUM(p.OrderQty) AS OrderQty
FROM [Purchase] p
INNER JOIN [Course] c
ON c.CourseID = p.CourseID
GROUP BY ROLLUP(YEAR(p.ModifiedDate), c.Name)
ORDER BY OrderDate

You want to exclude only the grand total row, while still returning:

Which WHERE clause should you add to achieve this?

Choose the correct answer from the options below.

Explanations for each answer:

Learn more about the GROUPING_ID function in SQL Server:
GROUPING_ID
Next Question