日期:2014-05-18  浏览次数:20449 次

求一条sql语句!!!
有两个表,一个是用户表user(userID,commentCount),一个是评论表comment(commentID,addUserID)。我想更新用户表的所有用户的commentCount字段,通过评论表计算出评论数,这条sql语句应该这么写?


------解决方案--------------------
update u
set
commentCount=(select isnull(count(*),0) from comment where addUserID=u.userID)
from
[user] u

------解决方案--------------------
update user set commentCount=(select count(*) from comment where addUserID=a.userID) from user a