select a.posttitle,a.createtime,a.createuser,a.createip, case when b.subtimes is null then '0' else b.subtimes end as subtimes, case when c.renumber is null then '0' else c.renumber end as renumber,d.retime,e.nickname,a.flag1,a.flag2,a.flag3,a.score,a.id ,datediff(hh,a.createtime,convert(varchar(19),getdate(),21)) as datediff from dbo.t_forum_post as a left outer join (select max(hit_subtimes) as subtimes,postid from dbo.t_hit where postid is not null group by postid ) as b on a.id=b.postid left outer join (select count(*) as renumber,papostid from dbo.t_forum_post where posttype='2' and papostid is not null group by papostid) as c on a.id=c.papostid left outer join (select max(createtime) as retime,papostid from dbo.t_forum_post where posttype='2' and papostid is not null group by papostid) as d on a.id=d.papostid left outer join dbo.t_user as e on a.createuser=e.id where a.posttype='1' and a.flag_available='1' and forumcode=?