34,587
社区成员
发帖
与我相关
我的任务
分享
create table hf(id int,hfid int,hfnr nvarchar(100))
第一个发消息的 hfid 为空,
以后,每个回复都写上回复对象的id,作为hfid,
要查的时候只要把表自连接,hfid连上id就行了.
create table hf(id int,hfid int,hfnr nvarchar(100))
--最先发表
insert into hf select 1,null,'abcdef'
--对最先发表的回复
insert into hf select 2,1,'faofwa'
insert into hf select 3,1,'fwnfsadf'
--对回复的回复
insert into hf select 4,3,'wuinfwe'
insert into hf select 5,2,'fwifm'
--其间还有对最先发表的回复
insert into hf select 6,1,'fvawe'
--获取对发表的回复:
select * from hf where hfid in(select id from hf where hfid is null)
go
drop table hf
/*
id hfid hfnr
----------- ----------- ----------------------------------------------------------------------------------------------------
2 1 faofwa
3 1 fwnfsadf
6 1 fvawe
(3 行受影响)
*/