Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在mysql中寻找包含多个属性的稠密秩_Mysql_Sql_Rank_Dense Rank - Fatal编程技术网

在mysql中寻找包含多个属性的稠密秩

在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

如何根据多个属性查找密集等级?

产品表有两列LastReceiptCost和ProductId

可以有两行具有相似的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/p:

如何在对产品id和LastReceiptcost进行排序的基础上找到排名 例如:

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