Sql查询tbl注释

发布于 2024-12-13 16:05:35 字数 706 浏览 2 评论 0原文

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] 和产品第 1 条评论 'CommentCommentId=""' 以及第 1 条评论的所有评论。

请帮助sql:)

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");

QUESTION:Produce, for the first comment made on a given Blog entry, any further comments made on that original comment only. The user should be prompted for the Blog entry’s unique identifier.

ANS SUPPOSE TO BE :

("1","I love shoes","10-3-2011","1","" ,"13"),
("2","I love shoes too","10-4-2011","1","1" ,"13")

Please help with sql

I want to be to do a self join to accept [BlogEntryId] and product 1st Comment 'CommentCommentId=""' and all the Comments on that 1st comment .

help with sql please:)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

与风相奔跑 2024-12-20 16:05:35

只需在原始查询中添加一点:

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))
    )

Just adding a bit to your original query:

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))
    )
捶死心动 2024-12-20 16:05:35

我猜你想要这样的东西:

select * 
from comment c
join comment subc on c.commentcommentid = subc.commentid
where c.commentid = @inputID

这是一个自连接。

我认为作业问题的答案很简单:

select *
from comment
where commentcommentid = @inputid

I guess you want something like this:

select * 
from comment c
join comment subc on c.commentcommentid = subc.commentid
where c.commentid = @inputID

This is a self join.

I think the answer to the homework question is simply this:

select *
from comment
where commentcommentid = @inputid
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文