本文介绍了如何从@curRank 获得排名位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

想要调用排名位置是否可以使用@curRank?

want to call up a ranking position is it posible with @curRank?

我用

    SELECT `item`, (`totalrate` / `nrrates`) AS `rank`, @curRank := @curRank 
+ 1 AS `ranking`  FROM `rtgitems`, (SELECT 

    @curRank := 0) r WHERE item
    REGEXP 'Total'
     ORDER BY (`totalrate` / `nrrates`)  DESC

我有一张桌子

item       rank      ranking 

Karla       9.5       1
Kelly       9.3       2
Arian       9.1429    3

在kelly页面我想调出她的排名

in the kelly page i want to call up her ranking position

    SELECT `item`, (`totalrate` / `nrrates`) 
AS `rank`, @curRank := @curRank + 1 AS `ranking` 
FROM `rtgitems`, 
(SELECT @curRank := 0) r WHERE item REGEXP 'kelly' 
ORDER BY (`totalrate` / `nrrates`) DESC LIMIT 10
echo "<td align='center' width='250'>" . $row['ranking'] . "</td>";  

但它只给我一个 1 而不是 2

but it only gives me a 1 instead of 2

推荐答案

您可以将 WHERE 子句移出排名计算结果.

You can move the WHERE clause out of ranking calculation results.

示例:

SELECT * FROM (
    SELECT
        `item`, (`totalrate` / `nrrates`) AS `rank`, 
        @curRank := @curRank + 1 AS `ranking` 
    FROM `rtgitems`, (SELECT @curRank := 0) r 
    ORDER BY (`totalrate` / `nrrates`) DESC 
    LIMIT 10
) results
WHERE item REGEXP 'kelly' 

这篇关于如何从@curRank 获得排名位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-21 14:03