首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

SQLServer 将两行数据合拢到一行

2013-04-05 
SQLServer 将两行数据合并到一行一、问题描述存储一个环结点的表,输出相邻环结点记录。环结点表如下:预期结

SQLServer 将两行数据合并到一行

一、问题描述

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

环结点表如下:

                         SQLServer 将两行数据合拢到一行

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

                 SQLServer 将两行数据合拢到一行    


二、解决方案

declare @minVertex intSelect @minVertex= min(Vertex) from CircleVertexselect vertex as parentVertex,isnull((select top 1 vertex from circleVertex R where R.id > T.id order by R.id    ),@minVertex) as childVertexfrom 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


期待您更好的解决方案!


热点排行