1

如何根据多个属性找到密集秩?

产品表有 2 列LastReceiptCostProductId

可以有 2 行具有相似的 ProductID 但不同的费率。

我只能根据 LastReceiptCost 找到排名。以下是 sql scipt ..

SELECT ProductID,
IF(@score=s.LastReceiptCost, @rank:=@rank, @rank:=@rank+1) rank,
@score:=s.LastReceiptCost Lcost
FROM ProductVendor s,
(SELECT @score:=0, @rank:=0) r
ORDER BY LastReceiptCost DESC,ProductID ;

下图显示了正在获取的 o/pi:排名输出

如何根据产品 id 和 LastReceiptcost 的排序来查找排名,如下所示:

ProductId    Lcost        Rank
AA         1450        1
AA         1350        2
AA         1300        3
BB         345         1
BB         345         1
BB         300         2
4

0 回答 0