【问题标题】:SQL What's wrong with my querySQL 我的查询出了什么问题
【发布时间】:2017-09-12 13:25:03
【问题描述】:
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 脚本短语返回布尔表达式而不是字符串

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'

【问题讨论】:

  • ¿消息错误?
  • #1064 - 你的语法有问题 obok ''players' WHERE 'id' IN(SELECT 'player_id' from 'players_online' WHERE 'frags'=(' 我需要保留这个单引号因为我想在lua脚本中提取一个字符串,当我离开引号时我得到一个布尔表达式而不是字符串
  • SQL 表单字符串文字中的单引号文本,而不是标识符。您的第一个查询尝试从字符串“players”中进行选择,这是无效的语法。您必须不使用引号或使用双引号。另外,请解释一下“短语”是什么意思(您的意思是“解析器”吗?)
  • 你的意思是BestPA=result.getDataString(BestPAl,"name")
  • 我已经通过使用两个查询解决了这个问题 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) 本地 BestPAm=db.storeQuery("SELECT name FROM players WHERE id = " .. BestPA ) 本地 nejm=result.getDataString(BestPAm, "名称") result.free(BestPAm)

标签: mysql sql lua


【解决方案1】:

表名和字段名不需要引号。试试这样

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;

【讨论】:

  • 是的,但是当我使用包含在 lua 中的短语时,我得到了一个布尔表达式而不是字符串=(SELECT MAX(frags) FROM player_online)) AND name is not null LIMIT 1;") BestPA=result.getDataString(BestPAl)
  • 我不熟悉 lua。例如,您可以尝试通过使用 mysql 工作台直接针对数据库运行查询来验证您的查询。
【解决方案2】:

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

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 中的这段代码是指在支持的程序中实现的自己的功能。

【讨论】:

    猜你喜欢
    • 2016-10-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多