SQL 查询出错了怎么办

SELECT 'name'  FROM 'players' WHERE 'id' IN
    (SELECT 'player_id' from 'players_online' WHERE 'frags'=
    (SELECT MAX(frags) FROM 'players_online'))
AND 'name' is not null LIMIT 1;

有两张表,第二张表中有一个非常重要的叫做 frags 的列,我想从第一张表中提取一个名字,其中 id 和 player_id 列具有相同的值。当我将它与无单引号的语句进行比较时,它可以正常工作,但我需要保留引号,因为 lua 脚本解析器会返回一个 bool 表达式而不是字符串。

Lua 代码:

BestPAl=db.storeQuery("SELECT name FROM players WHERE id IN(SELECT player_id from players_online WHERE frags=(SELECT MAX(frags) FROM players_online)) AND name is not null LIMIT 1;")
BestPA=result.getDataString(BestPAl)'code'
点赞
用户826422
用户826422

你不需要在表名和字段名加引号。尝试使用以下方式:

SELECT name FROM players WHERE id IN(SELECT player_id from players_online WHERE frags=(SELECT MAX(frags) FROM players_online)) AND name is not null LIMIT 1;
2017-04-16 22:30:41
用户7876092
用户7876092
以下是该问题的可能解决方案:

local BestPAl=db.storeQuery("SELECT player_id FROM players_online ORDER BY frags DESC LIMIT 1") local BestPA=result.getDataInt(BestPAl, "player_id") result.free(BestPAl) local BestPAm=db.storeQuery("SELECT name FROM players WHERE id = " .. BestPA )

```

我将查询拆成两段,每一段都存储在一个变量中。注意!这段代码是 Lua 语言中的自定义函数,需要在支持该程序的环境下运行。

2017-04-18 13:46:41