首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

求一条sql语句!该怎么处理

2012-01-11 
求一条sql语句!!!有两个表,一个是用户表user(userID,commentCount),一个是评论表comment(commentID,addUse

求一条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

热点排行