您的位置:首页 > 数据库

SQLServer 将两行数据合并到一行

2013-04-01 13:36 211 查看
一、问题描述

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

环结点表如下:



预期结果: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

期待您更好的解决方案!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: