相应的数据库结构为:
此主题相关图片如下:

查询练习的答案为:
查询1:
SELECT TOP 5 SUM(OrderDetails.Quantity) as TotalNum, Products.ModelName
FROM OrderDetails INNER JOIN Products ON OrderDetails.ProductID = Products.ProductID
GROUP BY Products.ModelName
ORDER BY TotalNum DESC
查询2:
declare @ProductID int
set @ProductID=378
--Protection_Guard Dog Pacifier
SELECT TOP 5 OrderDetails.ProductID,min(Products.ModelName),SUM(OrderDetails.Quantity) as TotalNum
FROM OrderDetails INNER JOIN Products ON OrderDetails.ProductID = Products.ProductID
WHERE OrderID IN (SELECT DISTINCT OrderID FROM OrderDetails WHERE ProductID = @ProductID) AND OrderDetails.ProductID != @ProductID
GROUP BY OrderDetails.ProductID
ORDER BY TotalNum DESC