微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

SQLServer 将两行数据合并到一行

一、问题描述

存储一个环结点的表,输出相邻环结点记录。

环结点表如下:

                         


预期结果:1->3,3->4,4->1.

                

    


二、解决方

declare @minVertex int
Select @minVertex= min(Vertex) from CircLevertex

select vertex as parentVertex,isnull((select top 1 vertex from circLevertex R
	 where R.id > T.id
	 order by R.id
    ),@minVertex) as childVertex
from circLevertex T

三、参考

[1].SQL Server combining 2 rows into 1 from the same table

[2].How to combine 2 rows into 1 from the same table


期待您更好的解决方案!

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐