0

我有一张很大的桌子。

每行都有一个 uniqueId 和一个 itemId。我想删除价格低于给定平均值的所有项目。我认为这样的事情应该可以工作,但它没有:

 DELETE FROM items GROUP BY itemId HAVING avg(price) < ?

SQLite 抱怨:

“GROUP”附近:语法错误

知道会发生什么吗?

4

3 回答 3

2
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" )
于 2012-08-22T06:27:46.110 回答
1

试试这个:

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
于 2012-08-22T06:21:07.377 回答
-1

我认为应该是这样的

DELETE FROM items WHERE itemId HAVING avg(price) < ?
于 2012-08-22T06:20:56.770 回答