我有一张定价规则表。我正在ProductTypeID
使用以下查询检索每个产品的最大折扣,这表明产品是哪种类型:
SELECT MAX(discount) as BiggestDiscount, ProductTypeID FROM dbo.SellingPriceRules
WHERE ProductTypeID is not null
GROUP by ProductTypeID
ORDER BY ProductTypeID
这非常有效,但是我需要对此进行扩展,并且对于ProductID
s 列表检索我最大的折扣。所以我需要找到ProductTypeID
每个ProductID
属于什么并检查我的SellPriceRules
数据库以获得最大折扣ProductTypeID
。
所以,在我的Discounts
桌子上,我有:
ProductID, Margin
在我的Products
表中,我有:
ProductID, ProductTypeID
为了获取每个产品的 ProductTypeID,我有:
select * from Discounts m
INNER JOIN Product p on p.ProductID = m.ProductID
WHERE ProductTypeID is not null
我现在正在努力将这两个查询结合在一起。我只是想获得折扣表中每种产品的最大折扣,然后从我的利润中减去。我怎样才能将这两个退休人员结合在一起?
非常感谢