SQL我的查询有什么问题

时间:2017-04-16 22:24:15

标签: mysql sql lua

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,我想从表1中提取一个名称,其中列id和player_id具有相同的值。当我检查它没有单引号它工作但我需要保持引用lua脚本的原因phser返回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'

2 个答案:

答案 0 :(得分:0)

表格和字段名称不需要引号。试试这个

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;

答案 1 :(得分:0)

好的,此问题的结果可能看起来像以前的解决方案:

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 )

我将查询分为两部分,每部分都写入变量。 Atention! lua中的这段代码指的是在支持的程序中实现的自己的函数。