0

我使用下面的查询来删除异常值(sd 的 1.5 倍)。

DELETE FROM sv_condition_sw 
WHERE snow_mountain > (
    SELECT AVG(snow_mountain)+1.5*STDDEV(snow_mountain) 
    FROM sv_condition_sw 
    WHERE lud='2012-11-28' AND res_id=769)
AND lud='2012-11-28' 
AND res_id=769

但是它给出了这个错误:

询问:delete FROM sv_condition_sw WHERE snow_mountain > (SELECT AVG(snow_mountain)+1.5*STDDEV(snow_mountain) FROM sv_condition_sw WHER...

Error Code: 1093
You can't specify target table 'sv_condition_sw' for update in FROM clause

我不知道这是什么意思。

4

1 回答 1

3

您可以使用另一个子选择来欺骗 MySQL

DELETE FROM sv_condition_sw 
WHERE snow_mountain > (select * from (SELECT AVG(snow_mountain)+1.5*STDDEV(snow_mountain) 
                                      FROM sv_condition_sw 
                                      WHERE lud='2012-11-28' 
                                      AND res_id=769) x)
 AND lud='2012-11-28' AND res_id=769
于 2012-11-29T17:29:40.533 回答