一、问题描述
存储一个环结点的表,输出相邻环结点记录。
环结点表如下:
预期结果:1->3,3->4,4->1.
二、解决方案
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
期待您更好的解决方案!