我在 MariaDB 中运行此选择,它按预期工作,它只是一个带有 exists 的选择:
select * from pred_loan_defaults d where exists (select 1 from pred_loan_defaults d2 where d.exec_id = d2.exec_id and d.loan_identifier = d2.loan_identifier and d2.default_status = 1 and d.prediction_date > d2.prediction_date) order by loan_identifier, prediction_date
现在,我正在尝试删除所选的行,因此我调整了语句:
delete from pred_loan_defaults d where exists (select * from pred_loan_defaults d2 where d.exec_id = d2.exec_id and d.loan_identifier = d2.loan_identifier and d2.default_status = 1 and d.prediction_date > d2.prediction_date);
但是我收到一个错误:
SQL 错误 [1064] [42000]: (conn=6) 您的 SQL 中有错误 句法;检查与您的 MariaDB 服务器对应的手册 在 'd 附近使用正确语法的版本
delete 语句有什么问题?
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
单表删除时表名后不能使用别名。
您需要使用
JOIN而不是WHERE EXISTS。delete d FROM pred_loan_defaults AS d JOIN prod_loan_defaults AS d2 ON d.exec_id = d2.exec_id AND d.loan_identifier = d2.loan_identifier AND d.prediction_date > d2.prediction_date WHERE d2.default_status = 1