我想对一些 Stack Overflow 帖子进行数据分析,并且需要以正确的格式获取查询输出。我的目标是输入 Post ID 并以下列格式获得我的答案:
ID|Title|Question|Answer1|Answer2|Answer3|Answer4|Answer5|Answer...
__________________________________________________________________
1 |Tit 1|Quest 1 |1.Answ |2.Answ |3.Answ |4.Answ |5.Answ |Answer...
2 |Tit 2|Quest 2 |1.Answ |2.Answ |3.Answ | | |
3 |Tit 3|Quest 3 |1.Answ |2.Answ |3.Answ |4.Answ | |
我不熟悉在 StackExchange 上编写查询,但我设法编写了一个查询以获得几乎正确的输出。我的结果是这样的:
ID|Title|Question|Answer|
_________________________
1 |Tit 1|Quest 1 |1.Answ |
1 |Tit 1|Quest 1 |2.Answ |
1 |Tit 1|Quest 1 |3.Answ |
2 |Tit 2|Quest 2 |2.Answ |
2 |Tit 2|Quest 2 |2.Answ |
2 |Tit 2|Quest 2 |2.Answ |
如您所见,我为每个答案复制了 ID、标题和问题。答案在列中,而不是并排。这是我设法编写的查询。有人可以帮助我或指出正确的方向吗?
select
p.Id, p.Title, p.Body, k.Body
from
Posts as p inner join
Posts as k on
p.id = k.parentid
where
p.Id in (##id##) and k.posttypeid=2