sql中用update更新count数据的问题

2024-12-14 13:39:14
推荐回答(3个)
回答1:

update user a set a.posts=
(select
b.counts
from
(select authorid,count(*) counts from post group by authorid) b
where a.uid=b.authorid)

回答2:

INSERT INTO user(uid,posts) (SELECT authorid,COUNT(authorid) FROM POST GROUP BY authorid)

解决问题!

回答3:

update user set posts = (select count(1) from post where authorid = user.uid)