请帮忙写个简单的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