想要调用排名位置是否可以与@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
在凯利页面中,我想打电话给她的排名位置
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
答案 0 :(得分:1)
您可以将WHERE
子句移出排名计算结果。
示例强>:
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'
答案 1 :(得分:0)
您可以使用以下任何一种解决方案:
这将为您提供排名为4的结果:
SELECT *
FROM
(
SELECT item, (`totalrate` / `nrrates`) AS `rank`,
@curRank := @curRank + 1 AS ranking
FROM rtgitems p, (SELECT @curRank := 0) r
ORDER BY (`totalrate` / `nrrates`) DESC
) AS stat
WHERE ranking = 2;
LIMIT OFFSET
来进行查询: SELECT item, (`totalrate` / `nrrates`) AS `rank`
FROM rtgitems
ORDER BY (`totalrate` / `nrrates`) DESC
LIMIT 4, 1