我有一张 table
scores(user, score)
我有这个问题
SET @row_num = 0;
SELECT @row_num := @row_num + 1 as row_index, user, score
FROM scores ORDER BY score DESC
现在我想从这个查询结果中选择名称为“john”且得分为“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
我该怎么做?
谢谢, 亚历山德罗
最佳答案
您还没有为派生表添加别名。
SELECT row_index FROM (...) AS alias
WHERE alias.user = 'john' AND alias.score = 1400
关于mysql - 从结果中选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14220306/