在MySQL中查询以逐行获取路由。从站点A到站点B

时间:2019-05-10 04:15:34

标签: mysql

我有一个非常简单的表,其中包含ID Primary KeySITE_XSITE_Y。例如,我要查询从site Asite F的路线,结果应该是这样的:

  • SITE_X-Y
  • AA-BB
  • BB-CC
  • CC-DD
  • DD-FF

SELECT a.ID AS id1,b.ID AS id2,a.SITE_X, a.SITE_Y, b.SITE_X, b.SITE_Y
FROM GRAFO_TESTE.teste_1 a
JOIN GRAFO_TESTE.teste_1 b
ON a.SITE_Y = b.SITE_X
WHERE a.SITE_X = 'AA'
OR b.SITE_Y = 'FF';

ID  SITE_X  SITE_Y
1   AA  BB
2   BB  CC
3   DD  EE
4   GG  FF
5   GG  HH
6   GG  CC
7   EE  FF

ROTA from site AA to site FF
SITE_X-Y
AA-BB
BB-CC
CC-DD
DD-FF

预期结果

enter image description here

0 个答案:

没有答案