我有一张很大的桌子。
每行都有一个 uniqueId 和一个 itemId。我想删除价格低于给定平均值的所有项目。我认为这样的事情应该可以工作,但它没有:
DELETE FROM items GROUP BY itemId HAVING avg(price) < ?
SQLite 抱怨:
“GROUP”附近:语法错误
知道会发生什么吗?
DELETE
FROM items as i1
WHERE i1.itemID in (
Select i2.itemID
FROM items as i2
GROUP BY i2.itemId
HAVING avg(price) < "user defined threshold" )
试试这个:
delete I
from items I join
(select itemId,avg(price) as price
from items
GROUP BY itemId)a
on I.itemId=a.itemId
where I.price<a.price
我认为应该是这样的
DELETE FROM items WHERE itemId HAVING avg(price) < ?