据我所知,你需要每个帖子的回复。
我用post_id、user_id和reply_id创建了一个表,并插入了一些伪值。
create table t1
(id int, user_id int,reply int);
insert into t1 values(100,1,0);
insert into t1 values(101,2,100);
insert into t1 values(102,1,100);
insert into t1 values(103,2,0);
insert into t1 values(104,3,103);
然后,一个简单的自连接将为您提供对每个帖子的回复,其中包含以下代码。
select a.id,a.user_id,count(b.reply)
from t1 a
left join t1 b
on a.id=b.reply
group by 1,2;