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

请帮忙写个简单的SQL语句解决办法

2012-01-19 
请帮忙写个简单的SQL语句分2表用户表memberdata字段uid是用户ID,postnum是发帖数(出错的字段)帖子表posts

请帮忙写个简单的SQL语句
分2表
用户表   memberdata
字段       uid是用户ID,postnum是发帖数(出错的字段)

帖子表   posts
字段       authorid是发帖用户ID,等于用户表中的uid

select   count(*)   from   posts   where   authorid=5773   group   by   authorid
可以查询到发帖数是3106

谁能帮我写个连接语句,直接查询到后修改用户表的postnum数据?我写的这个肯定是错了的........
update   memberdata   set   memberdata.postnum=(select   count(*)   from   posts   group   by   pw_posts.authorid)   where   memberdata.uid=posts.authorid

[解决办法]
--or:
update a set a.postnum=b.num
from memberdata a,(select authorid, count(*) as num from posts group by authorid) b
where a.uid=b.num

热点排行