我正在尝试返回我们客户数据库中订购最多的 2 个商品。以下是我订购最多的商品的内容,但我无法弄清楚如何为第二次订购最多的商品创建另一列。
创建第二列的最佳方法是什么?
SELECT FirstName, EmailAddress, Id, PreferredLocationId,
(
SELECT TOP 1 [Description] FROM [Order] o
INNER JOIN [OrderItem] oi ON oi.OrderId = o.OrderId
WHERE o.CustomerId = Customer.Id
GROUP BY [Description]
ORDER BY COUNT(*) DESC
) AS MostOrderedItem
FROM Customer
GROUP BY FirstName, EmailAddress, Id, PreferredLocationId