Comment:tbl
CommentId PK
CommentEntry
CommentDate
Category
CommentCommentId
BlogEntryId FK
Insert into Comment(CommentId, CommentEntry, CommentDate, Category, CommentCommentId, BlogEntryId)
Values("1","I love shoes","10-3-2011","1","" ,"13"),
("2","I love shoes too","10-4-2011","1","1" ,"13"),
("3","There nice shoes in the mall","2","","13");问:对于给定博客条目上的第一条评论,只对该原始评论产生任何进一步的评论。应该提示用户输入博客条目的唯一标识符。
ANS应该是:
("1","I love shoes","10-3-2011","1","" ,"13"),
("2","I love shoes too","10-4-2011","1","1" ,"13")请帮助了解sql
我想要做一个自我连接,接受BlogEntryId和产品第一个评论'CommentCommentId=""‘和第一个评论上的所有评论。
有关sql的帮助:)
发布于 2011-11-06 13:38:42
只需在原始查询中添加一点:
SELECT *
FROM Comment
WHERE BlogEntryId = [?Blog Entry]
AND (
CommentId = (SELECT CommentId FROM Comment WHERE CommentDate = (SELECT min(CommentDate) from Comment))
OR
CommentCommentId = (SELECT CommentId FROM Comment WHERE CommentDate = (SELECT min(CommentDate) from Comment))
)发布于 2011-11-06 13:29:20
我猜你想要这样的东西:
select *
from comment c
join comment subc on c.commentcommentid = subc.commentid
where c.commentid = @inputID这是一个自连接。
我认为家庭作业问题的答案很简单:
select *
from comment
where commentcommentid = @inputidhttps://stackoverflow.com/questions/8025223
复制相似问题