SQL Server 更新グループ 質問する

SQL Server 更新グループ 質問する

MS-SQLでこれを実行しようとしていますが、Group by行でエラーが返されます

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

パフォーマンスを良好に保ちながらこの問題を解決する方法を知っている人はいますか。

ベストアンサー1

試す

;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 

おすすめ記事