22,223
社区成员
发帖
与我相关
我的任务
分享
create table post
(
id int auto_increment primary key, \\帖子的ID
tid int not null, \\父帖的ID
subject varchar(50) default '', \\帖子的标题
dateline timestamp default current_timestamp, \\帖子发布时间,默认当前时间
message text not null, \\帖子内容
author varchar(20) not null \\帖子作者
);
select *,count(*) as total from (select * from post order by dateline desc) as posts group by tid order by dateline desc;
--如果你的主题帖也算回复数的话。
--看你要哪个?
select * ,(select count(1) from post where tid=a.id) 回复数 from post a where id=tid order by dateline desc
请给出表结构,测试数据,相关算法和需要的结果.谢谢!
select * ,(select count(1) from post where tid=a.id and tid<>id ) 回复数 from post a where id=tid order by dateline desc
with Args as
(
select * from post
union all
select * from post where post.id = Args.id
)
select * ,row_number over(order by id) from Args ;