0

I’m working with a large database and I’m trying to delete data outliers. I found this code from a previous question and I modified it to work with my database.

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' ) x)
AND lud='2012-11-28' 

It works great with one exception.

I have thousands of “lud”s or products in my case. How could I delete each lud (or product) with one query?

4

1 回答 1

0

Could you try something like

DELETE sv_condition_sw 
FROM sv_condition_sw, 
   (SELECT AVG(snow_mountain)+1.5*STDDEV(snow_mountain) as threshold, lud
   FROM sv_condition_sw GROUP BY lud) as t
WHERE sv_condition_sw.snow_mountain > t.threshold
AND sv_condition_sw.lud=t.lud

This should work in MySQL as well.

于 2013-08-05T19:22:54.777 回答