gpt4 book ai didi

java - SQL 语法错误 : when passing nested query in executeQuery() method

转载 作者:行者123 更新时间:2023-11-29 10:12:32 27 4
gpt4 key购买 nike

抱歉问了这么愚蠢的问题。

下面是实际的查询:

SELECT  DATE_FORMAT(b.maxtime, "%H:%i") as ts, b.max_value-b.min_value as 
diff FROM (SELECT max(Anzahl) as max_value ,min(Anzahl) as min_value,
greatest(max(ts),min(ts)) as maxtime
FROM customer where ts rlike '^2017-06-06' and Typ="B4A"
GROUP BY hour(ts)) b;

当我使用 java 将其传递到 executeQuery() 方法时,如下所示:

resultset =statement.executeQuery("SELECT DATE_FORMAT(b.maxtime,\"%H:%i\") 
as ts, b.max_value-b.min_value as diff(SELECT max(Anzahl) as max_value
,min(Anzahl) as min_value, max(ts) as maxtime from customer where Typ = " +
"\"" + selected_value+"\""+" "+"and ts RLIKE"+"'^"+cal_value+"'"+ "GROUP BY
hour(ts))b");

我在 SQL 语法中遇到错误。错误是:

MySQL server version for the right syntax to use near '(SELECT max(Anzahl) as max_value ,min(Anzahl) as min_value, max(ts) as maxtime f' at line 1

有人可以帮我解决这个问题吗?

最佳答案

这是一个错字。在实际查询中,...b.min_value 之后有一个 FROM 作为差异。您已将其遗漏在要解析为 executeQuery()

的字符串中
...diff FROM (SELECT max(Anzahl)...
<小时/>

所以完整的声明是

resultset = statement.executeQuery("SELECT DATE_FORMAT(b.maxtime,\"%H:%i\") 
as ts, b.max_value-b.min_value as diff FROM (SELECT max(Anzahl) as max_value
,min(Anzahl) as min_value, max(ts) as maxtime from customer where Typ = " +
"\"" + selected_value+"\""+" "+"and ts RLIKE"+"'^"+cal_value+"'"+ "GROUP BY
hour(ts))b");

关于java - SQL 语法错误 : when passing nested query in executeQuery() method,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50717181/

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