Zadanie 11.

Oblicz, ile było zamówień na towary każdej kategorii w skali każdego roku.

Baza: Northwind, Tabele: dbo.Orders, dbo.Order Details, dbo.Products, dbo.Categories, Kolumny: OrderDate, CategoryName, OrderID, Wynik: 24 rows

16

Rozwiązanie

SELECT YEAR(O.OrderDate) as Rok, C.CategoryName, Count(O.OrderID) as Zamowienia FROM dbo.Orders as O

JOIN dbo.[Order Details] as OD on O.OrderID = OD.OrderID

JOIN dbo.Products as P on P.ProductID = OD.ProductID

JOIN dbo.Categories as C on C.CategoryID = P.CategoryID

GROUP BY C.CategoryName, YEAR(O.OrderDate)

ORDER BY Rok, C.CategoryName;

[collapse]