
Answer-first summary for fast verification
Answer: SELECT ItemID, ItemName, SUM(Quantity) AS TotalQuantity FROM Inventory WHERE StockDate >= DATEADD(year, DATEDIFF(year, 0, GETDATE()), 0) GROUP BY ItemID, ItemName;
Option A correctly sums the quantities for each item and filters the inventory to include only those from the current year. Options B, C, and D either do not filter the date correctly or do not sum the quantities correctly.
Author: LeetQuiz Editorial Team
Ultimate access to all questions.
You are tasked with querying a warehouse in Fabric to extract inventory data for the current year. The warehouse contains a table named 'Inventory' with columns 'ItemID', 'ItemName', 'StockDate', and 'Quantity'. Write a SQL query that retrieves the total quantity of each item for the current year. How would you structure this query?
A
SELECT ItemID, ItemName, SUM(Quantity) AS TotalQuantity FROM Inventory WHERE StockDate >= DATEADD(year, DATEDIFF(year, 0, GETDATE()), 0) GROUP BY ItemID, ItemName;
B
SELECT ItemID, ItemName, SUM(Quantity) AS TotalQuantity FROM Inventory GROUP BY ItemID, ItemName;
C
SELECT ItemID, ItemName, Quantity AS TotalQuantity FROM Inventory WHERE StockDate >= DATEADD(year, DATEDIFF(year, 0, GETDATE()), 0);
D
SELECT ItemID, ItemName, Quantity AS TotalQuantity FROM Inventory;
No comments yet.