我在 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
Run Code Online (Sandbox Code Playgroud)
现在,我尝试删除所选的行,因此我调整了语句:
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);
Run Code Online (Sandbox Code Playgroud)
但我收到一个错误:
SQL 错误 [1064] [42000]: (conn=6) 您的 SQL 语法有错误;检查与您的 MariaDB 服务器版本相对应的手册,了解使用近 'd 的正确语法
该声明有什么问题吗delete?
单表删除时不能在表名后使用别名。
您需要使用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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
392 次 |
| 最近记录: |