【问题标题】:syntax Error/bad SQL grammar in Build time构建时的语法错误/错误的 SQL 语法
【发布时间】:2019-11-14 13:04:34
【问题描述】:

这是我在我的 java 文件中使用的查询。我在 Oracle SQL 开发人员中尝试过它,它按预期工作。但我在构建时遇到错误。

 private static final String FIND_TOTALS_BY_STATUS_FOR_HEADER = "SELECT status, count(status) FROM uh_task_executions t1 WHERE th_task_execution_header_id_fk = ?"
        + "AND start_time IN  (SELECT start_time FROM uh_task_executions t2 WHERE th_task_execution_header_id_fk = ? and t1.target = t2.target) GROUP BY status";

脚本:

SELECT status, count(status) FROM uh_task_executions t1 WHERE th_task_execution_header_id_fk = 10047
AND start_time IN  (SELECT start_time FROM uh_task_executions t2 WHERE th_task_execution_header_id_fk = 10047 and t1.target = t2.target) GROUP BY status

错误信息

PreparedStatementCallback;错误的 SQL 语法 [SELECT 状态, 计数(状态)来自 uh_task_executions t1 WHERE th_task_execution_header_id_fk = ? AND start_time IN(选择 start_time FROM uh_task_executions t2 WHERE th_task_execution_header_id_fk = ?和 t1.target = t2.target) 分组 状态];嵌套异常是 java.sql.SQLSyntaxErrorException: You SQL 语法 有错误;检查手册 对应于您的 MySQL 服务器版本,以便使用正确的语法 'start_time IN 附近(从 uh_task_executions t2 选择 start_time WHERE th_task_execu' 在第 1 行

【问题讨论】:

    标签: mysql oracle


    【解决方案1】:

    在这里添加空格:

    + " AND start_time IN ...
       ^
       |
      here
    

    另外,您宁愿在任何地方都使用表别名,否则您可能会得到意想不到的结果。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多