使用此查询时,我得到了我想要的结果,但我需要合并 Beer.Name 实例。这样,当我想将 CustomerID 和 Beer.Name 合并为单个实体时,我的输出中有多个 Beer.Name 条目及其数量。我该怎么做?
SELECT C.CustomerID, Beer.Name,sum (quantitysupplied)as 'Total Quantity'
FROM Customer C
INNER JOIN CustomerOrder
ON C.CustomerID = CustomerOrder.CustomerID
INNER JOIN CustomerOrderLine
ON CustomerOrderLine.CustomerOrderID = CustomerOrder.CustomerOrderID
INNER JOIN Product
ON CustomerOrderLine.ProductID =Product.ProductID
INNER JOIN Beer
ON Product.BeerID = Beer.BeerID
GROUP BY C.CustomerID, Beer.Name, CustomerType
HAVING CustomerType LIKE 'C'
谢谢你。
这是输出:
CustomerID Name Total Quantity
----------- ------------------------------ --------------
1001 Ale Heads 11
1002 Ale Heads 8
1003 Ale Heads 13
1004 Ale Heads 3
1006 Ale Heads 4
1007 Ale Heads 14
1008 Ale Heads 4
1009 Ale Heads 4
它很长,但它很有代表性,我只想将啤酒名称和客户 ID 的一个实例合并到其他东西中。