選擇我有一個表MySQL的 - 從結果
scores(user, score)
,我有這個疑問
SET @row_num = 0;
SELECT @row_num := @row_num + 1 as row_index, user, score
FROM scores ORDER BY score DESC
現在我要選擇,從這個查詢結果,與名的用戶「約翰」和得分'1400'知道他的row_index是什麼,像
SELECT row_index
FROM *result* WHERE user='john' AND score=1400
我該怎麼做?我試圖
SET @row_num = 0;
SELECT row_index
FROM (SELECT @row_num := @row_num + 1 as row_index, user, score
FROM scores ORDER BY score DESC)
WHERE user='john' AND score=1400`
但phpMyAdmin的說
#1248 - Every derived table must have its own alias
我怎麼能這樣做?
謝謝 亞歷山德羅
謝謝你,這對我幫助很大,我認爲這是做的最快方式。 – BackSlash