可以使用 HAVING 子句进行删除吗? [英] Possible to do a delete with a HAVING clause?
本文介绍了可以使用 HAVING 子句进行删除吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想做如下事情:
DELETE UserPredictions
GROUP BY UserId
HAVING COUNT(*) < 500
但是我遇到了语法错误.甚至可以在 SQL Server 中使用 HAVING 子句进行删除,还是必须将计数汇总到 CTE 中并使用连接进行删除?
But I'm getting a syntax error. Is it even possible to do a delete with a HAVING clause in SQL Server or will I have to roll the counts up into a CTE and do a delete with a join?
推荐答案
并非如此.have 子句意味着聚合,这意味着您不再拥有原始行.
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)
这篇关于可以使用 HAVING 子句进行删除吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文