34,587
社区成员
发帖
与我相关
我的任务
分享
select distinct topicid
from @message
group by topicid
having count(*) >= 1 and Userid='当前用户ID' and Replyto is not null
order by posted desc
[Quote=引用 5 楼 jianjialin 的回复:]
不好意思 刚刚下班走的急 没有说清楚。
SQL code
declare @message table(
messageid int identity(1,1) primary key,
topicid int,--外键 主题表ID
Replyto int,--外键 userid(就是帖子发出人的ID。 如果是发帖 ,那么这为NULL; 如果是跟帖, 则为发帖者的ID)
userid int, --本条信息发出者(跟帖者ID 或者发帖者ID)
posted datetime--发布时间
)
想求当前用户的回复过的帖子的…
[/Quote]
select distinct topicid from @message where Userid='当前用户ID' and Replyto is not null --Replayto isnotnull则表示我回帖
order by posted desc
select distinct topicid from @message where Userid='当前用户ID' and Replyto is not null --Replayto isnotnull则表示我回帖
--distinct 用于去掉结果中的重复行
order by posted desc
select topicid from @message where Userid='当前用户ID' and Replyto is not null --Replayto isnotnull则表示我回帖
group by topicid order by posted desc
select topicid from @message where Replyto = '当前登录ID' order by posted desc
select messageid
from @message
where Replyto = '当前登录ID'
order by posted desc
select messageid ,
topicid ,
Replyto ,
userid ,
posted
from Tab
where Replyto = '当前登录ID'
order by posted desc