【发布时间】:2019-10-19 07:25:12
【问题描述】:
我如何获得每个供应商最畅销的产品?
到目前为止,我想出了这个,但似乎无法继续。
select vendor.Vendor_Name, Product.category AS Product
, SUM(SalesFacts.Price * SalesFacts.Quantity) AS [Total Revenue]
FROM Vendor, Product, SalesFacts
WHERE SalesFacts.Vendor_Key = Vendor.Vendor_Key
AND SalesFacts.Product_Key = Product.Product_Key
GROUP BY vendor.Vendor_Name, product.Category
ORDER BY [Total Revenue] DESC;
(Product_Key 和 Vendor_Key 是外键)
【问题讨论】:
-
进化 - 进入 21 世纪,停止使用 old-style joins。
标签: sql sql-server