日期:2014-05-17 浏览次数:20565 次
CREATE TABLE [ExpertReply](
[ID] [int] NOT NULL,
[UserID] [int] NOT NULL,
[BlogID] [int] NOT NULL,
[CommentID] [int] NOT NULL,
[Context] [nvarchar](max) NULL,
[CreateTime] [datetime] NOT NULL,
)
insert ExpertReply values(1, 1, 1, 0, '回复1', GETDATE())
insert ExpertReply values(2, 2, 1, 0, '回复2', GETDATE())
insert ExpertReply values(3, 3, 1, 0, '回复3', GETDATE())
insert ExpertReply values(4, 4, 1, 2, '评论1', GETDATE())
insert ExpertReply values(5, 3, 1, 3, '评论3', GETDATE())
insert ExpertReply values(6, 2, 1, 2, '评论2', GETDATE())
insert ExpertReply values(7, 3, 1, 3, '评论4', GETDATE())
with tb as(select id,commentid=id,context from [ExpertReply] where commentid=0
union all
select a.id,tb.commentid,a.context from tb,[ExpertReply] a where tb.id=a.commentid
)
select context from tb
order by commentid,id
--CREATE TABLE [ExpertReply](
-- [ID] [int] NOT NULL,
-- [UserID] [int] NOT NULL,
-- [BlogID] [int] NOT NULL,
-- [CommentID] [int] NOT NULL,
-- [Context] [nvarchar](max) NULL,
-- [CreateTime] [datetime] NOT NULL,
--)
--insert ExpertReply values(1, 1, 1, 0, '回复1', GETDATE())
--insert ExpertReply values(2, 2, 1, 0, '回复2', GETDATE())
--insert ExpertReply values(3, 3, 1, 0, '回复3', GETDATE())
--insert ExpertReply values(4, 4, 1, 2, '评论1', GETDATE())
--insert ExpertReply values(5, 3, 1, 3, '评论3', GETDATE())
--insert ExpertReply values(6, 2, 1, 2, '评论2', GETDATE())
----insert ExpertReply values(7, 3, 1, 3, '评论4',&nb