delete from t_table where num < ( select avg(num) from
t_table)
執行報錯。哪裡錯了嗎?還是有其他方法?
不能先select出同一表中的某些值,再update/delete這個表(在同一語句中)
樓上說的是一種解決方法,也可以這樣寫,兩種都可以
delete from t_table where num < (select avg(num) as num from (select * from t_table)c);
delete from t_table where num < (select * from (select avg(num) as num from t_table)v);
注:as num和最後的c或v別忘記