我有两张table。第一个表包含城市:
Cities
a
b
c
d
f
另一张表显示了城市之间的距离:
start city destination city distance
1 2 100
1 3 150
2 4 215
3 4 125
3 5 210
我想找出给定表中两个城市之间的最短距离。我该怎么做?
2条答案
按热度按时间t9eec4r01#
表之间没有公共列。此外,您还可以使用最短路径算法来实现这一点。请按以下链接执行:
https://www.mssqltips.com/sqlservertip/5540/using-tsql-to-find-the-shortest-distance-between-two-points/
基于t-sql的最短路径算法
jpfvwuh42#
下面是使用cte查询两个城市的最短距离和出行路径。