我正在尝试执行此查询。删除所有小于account
表中所有帐户平均值的帐户。但是,我收到此错误:
#1093 - Table 'account' is specified twice, both as a target for 'DELETE' and as a separate source for data
查询为:
DELETE
FROM account WHERE account_number IN
(
SELECT account_number FROM account
WHERE balance < (SELECT AVG (balance) FROM account)
);
我该如何解决这个问题?
答案 0 :(得分:1)
使用JOIN
:
DELETE a
FROM account a JOIN
(SELECT AVG(balance) as avg_balance
FROM account
) ab
ON a.balance < ab.avg_balance;