我想修改以下查詢來查找特定的videoid的排名,我沒有太多的運氣任何人都可以提出一個解決方案?MySQL查詢幫助查找排名ID
SELECT videoid wins/loses as win_loss,
@curRank := @curRank + 1 AS rank
FROM cb_video,
(SELECT @curRank := 0) r
ORDER BY wins/loses DESC
我試着做一個子查詢這樣的,但它失敗:
SELECT rank
FROM (SELECT videoid wins/loses as win_loss,
@curRank := @curRank + 1 AS rank
FROM cb_video,
(SELECT @curRank := 0) r
ORDER BY wins/loses DESC)
WHERE videoid = 116
還增加了視頻ID到WHERE無子查詢子句只是始終顯示排名是排名第一的位置,因爲它只有返回一行:
SELECT videoid wins/loses as win_loss,
@curRank := @curRank + 1 AS rank
FROM cb_video,
(SELECT @curRank := 0) r
WHERE videoid = 116
ORDER BY wins/loses DESC
任何想法如何限制結果到一個特定的ID,但仍然保持排名?僅供參考如果有幫助,我會保留兩列(勝利和失敗)。
你的第二種方法似乎對我來說。你得到了什麼錯誤? – a1ex07 2011-06-01 01:54:34
IME,如果表引擎是MyISAM,則不可信賴變量排名功能。數字會跳過... – 2011-06-01 02:46:16