Possible to do a delete with a HAVING clause?

前端 未结 5 1514
野性不改
野性不改 2020-12-06 04:02

I want to do something like below:

DELETE UserPredictions
  GROUP BY UserId
  HAVING COUNT(*) < 500

But I\'m getting a syntax error. Is

5条回答
  •  执笔经年
    2020-12-06 04:37

    Not really. The having clause implies an aggregation, which means you don't have the original rows any more.

    I think you want the following:

    DELETE from UserPredictions
    where UserId in (select UserId from UserPredictions group by UserId having count(*) < 500)
    

提交回复
热议问题