SQL Server更新组 [英] SQL Server Update Group by
本文介绍了SQL Server更新组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图在MS-SQL上执行此操作,但仅在按行分组时返回了一个错误
I'm trying to execute this on MS-SQL but returns me an error just at the Group by line
update #temp
Set Dos=Count(1)
From Temp_Table2010 s
where Id=s.Total and s.total in (Select Id from #temp)
group by s.Total
有谁知道我该如何解决这个问题,并且表现良好。
Do anyone knows how can I solve this problem having good performance.
推荐答案
试试
Try
;with counts
AS
(
SELECT total, COUNT(*) as dos
FROM temp_table2010
WHERE total in (select id from #temp)
)
UPDATE T
SET dos=counts.dos
FROM #temp T
INNER JOIN counts
ON t.id = counts.total
这篇关于SQL Server更新组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文