我需要此信息来返回每个城市为每种产品提供的总数量,但我缺少了一些东西:
SELECT Tb_Supplier.City,
Tb_Product.Name,
SUM(Tb_Offers.Quantity) "Quantity Offered"
FROM Tb_Supplier, Tb_Product, Tb_Offers
WHERE Tb_Supplier.Supp_ID = Tb_Offers.Supp_ID AND
Tb_Offers.Prod_ID = Tb_Product.Prod_ID
GROUP BY Tb_Supplier.City, Tb_Product.Name, Tb_Offers.Quantity
ORDER BY Tb_Supplier.City, Tb_Product.Name;
结果如下所示:
Name Name City Quantity Sold
Bernstein TV Chicago 720
Bernstein TV Chicago 3600
Bernstein TV Chicago 7200
Bernstein TV Cleveland 7200
Bernstein TV Lansing 10800
Bernstein TV Lansing 75600
Bernstein TV Lansing 108000
Bernstein TV Madison 10800
Bernstein TV Madison 36000
Bernstein TV Stevens Point 1080
Bernstein TV Stevens Point 7200
Bernstein TV Stevens Point 12600
Bernstein TV Wausau 14400
Bernstein TV Wausau 36000
Herman TV Lansing 144000
Herman TV Stevens Point 72000
Joel TV Lansing 216000
Joel TV Stevens Point 72000
Wolf TV Stevens Point 72000
我认为我需要使用DISTINCT。请问有人可以帮我吗?
答案 0 :(得分:0)
您需要删除:
Tb_Offers.Quantity
来自分组。
这是您需要分组的内容:
GROUP BY Tb_Supplier.City, Tb_Product.Name
然后,您为Tb_Offers.Quantity
进行汇总。