0

再会。我的 Java 代码中有一个删除表中重复行的查询。最初它起作用了,有一段时间我没有接触这个项目。但是几天前在运行该文件时,我的代码抛出了异常。这是我的代码:

String query = "DELETE error_log FROM error_log INNER JOIN "
                + "(SELECT  min(id) minid, service_source, channel,transaction_type, provider_name,     pido_account, beneficiary_id, error_description, error_date FROM error_log "
                + "GROUP BY service_source, channel, transaction_type, provider_name, pido_account, beneficiary_id, error_description, error_date "
                + "HAVING COUNT(1) > 1 AS duplicates ON "
                        + "(duplicates.service_source = error_log.service_source AND duplicates.channel = error_log.channel "
                    + "AND duplicates.transaction_type = error_log.transaction_type AND duplicates.provider_name = error_log.provider_name "
                    + "AND duplicates.pido_account = error_log.pido_account AND duplicates.beneficiary_id = error_log.beneficiary_id "
                    + "AND duplicates.error_description = error_log.error_description AND duplicates.error_date = error_log.error_date "
                    + "AND duplicates.minid <> error_log.id"
                        + ")"
                    + ")";

        int deploy = duplicate.executeUpdate(query);

之后我得到这个:

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以获取正确的语法,以便在第 1 行的 'AS duplicates ON (duplicates.service_source = error_log.service_source AND dupli' 附近使用。

我该如何纠正这个问题并从表中删除重复项?

4

1 回答 1

0

你有一个缺失 )的在线+ "HAVING COUNT(1) > 1 AS duplicates ON ",最后有一个额外)的。

String query = "DELETE error_log FROM error_log INNER JOIN "
                + "(SELECT  min(id) minid, service_source, channel,transaction_type, provider_name,     pido_account, beneficiary_id, error_description, error_date FROM error_log "
                + "GROUP BY service_source, channel, transaction_type, provider_name, pido_account, beneficiary_id, error_description, error_date "
                + "HAVING COUNT(1) > 1 ) AS duplicates ON "
                        + "(duplicates.service_source = error_log.service_source AND duplicates.channel = error_log.channel "
                    + "AND duplicates.transaction_type = error_log.transaction_type AND duplicates.provider_name = error_log.provider_name "
                    + "AND duplicates.pido_account = error_log.pido_account AND duplicates.beneficiary_id = error_log.beneficiary_id "
                    + "AND duplicates.error_description = error_log.error_description AND duplicates.error_date = error_log.error_date "
                    + "AND duplicates.minid <> error_log.id"
                    + ")";

        int deploy = duplicate.executeUpdate(query);

如果您没有进行任何更改并且它停止工作,1)您确定您测试了此代码吗?2) 是否有其他人在您不知情的情况下进行了任何更改?

于 2013-09-11T16:10:08.197 回答