gpt4 book ai didi

sql - TSQL 选择排序列与 Prev Current Next

转载 作者:塔克拉玛干 更新时间:2023-11-03 06:01:00 25 4
gpt4 key购买 nike

我有一个包含这些列的表格:

+-----------+--------------+-----------+
|PrevStation|CurrentStation|NextStation|
+-----------+--------------+-----------+
|- |A |B |
+-----------+--------------+-----------+
|A |B |C |
+-----------+--------------+-----------+
|B |C |D |
+-----------+--------------+-----------+
|C |D |E |
+-----------+--------------+-----------+
|D |F |- |
+-----------+--------------+-----------+

现在我想通过以下方式表示一个 View :

+---------------+
|ClosestStations|
+---------------+
|A |
+---------------+
|B |
+---------------+
|C |
+---------------+
|D |
+---------------+
|E |
+---------------+
|F |
+---------------+

*注意:我想要排序的行与第一个表的约定*

您认为解决方案如何?

最佳答案

试试这个

Select [CLoseStation] from
(
select PrevStation AS [CLoseStation],PrevStation ,NextStation,CurrentStation
From T
Union
Select NextStation AS [CLoseStation],PrevStation ,NextStation,CurrentStation
From T
union
Select CurrentStation AS [CLoseStation],PrevStation ,NextStation,CurrentStation
From T
) AS S Order By PrevStation ,NextStation,CurrentStation ASC

关于sql - TSQL 选择排序列与 Prev Current Next,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21083356/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com