[英]Multiple row in self join
i have table in this format 我有这种格式的桌子
Id QId ResourceId ModuleId SubProjId Comments
1 1 1 1 2 ffdg 1 1
2 2 1 1 2 dfgfdg 1 1
3 3 1 1 2 hgjhg 1 1
4 1 2 1 2 tryty 1 0
5 5 1 1 2 sdf 1 1
6 5 2 1 2 ghgfh 1 0
7 7 2 1 2 tytry 1 0
8 3 2 1 2 rytr 1 0
and i wan result in this way 我希望这样
qid ResourceId Comments ResourceId Comments
1 1 ffdg 2 tryty
3 1 hgjhg 2 rytr
i tried 我试过了
select distinct A.qid,A.ResourceId,A.Comments,B.ResourceId,b.Comments
from dbo.#temp A inner join #temp B on A.QId=B.QId and A.[ModuleId]=B.[ModuleId] and a.[SubProjId]=b.[SubProjId]
but did not find any luck please help 但没有发现任何运气请帮助
You want to convert vertical data to horizontal. 您想要将垂直数据转换为水平数据。 So you need to create a pivot table. 因此,您需要创建一个数据透视表。 You can find more details here How to transform vertical data into horizontal data with SQL? 您可以在此处找到更多详细信息如何使用SQL将垂直数据转换为水平数据?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.