gpt4 book ai didi

mysql - 从结果中选择

转载 作者:行者123 更新时间:2023-11-29 04:10:02 28 4
gpt4 key购买 nike

我有一张 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/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com