在mysql中寻找包含多个属性的稠密秩
如何根据多个属性查找密集等级? 产品表有两列LastReceiptCost和ProductId 可以有两行具有相似的ProductID,但速率不同 我只能根据LastReceiptCost找到排名。下面是该排名的sql scipt在mysql中寻找包含多个属性的稠密秩,mysql,sql,rank,dense-rank,Mysql,Sql,Rank,Dense Rank,如何根据多个属性查找密集等级? 产品表有两列LastReceiptCost和ProductId 可以有两行具有相似的ProductID,但速率不同 我只能根据LastReceiptCost找到排名。下面是该排名的sql scipt SELECT ProductID, IF(@score=s.LastReceiptCost, @rank:=@rank, @rank:=@rank+1) rank, @score:=s.LastReceiptCost Lcost FROM ProductVendor
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/p:
如何在对产品id和LastReceiptcost进行排序的基础上找到排名
例如:
ProductId Lcost Rank
AA 1450 1
AA 1350 2
AA 1300 3
BB 345 1
BB 345 1
BB 300 2
见