我有两个mysql表:节点和关系
CREATE TABLE `nodes` (
`id` int(10) unsigned NOT NULL auto_increment,PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `relations` (
`node_id` int(10) unsigned NOT NULL,`related_node_id` int(10) unsigned NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
假设节点中有四行:节点1和2共享一个关系,节点2和3,1和4,4和3
INSERT INTO `relations` VALUES (1,2);
INSERT INTO `relations` VALUES (2,3);
INSERT INTO `relations` VALUES (1,4);
INSERT INTO `relations` VALUES (4,3);
是否有任何算法可以获取相关节点之间的路径?喜欢
+---------+------------------+---------+
| node_id | related_node_id | route |
+---------+------------------+---------+
| 1 | 2 | 1/2 |
| 2 | 3 | 2/3 |
| 1 | 4 | 1/4 |
| 4 | 3 | 4/3 |
| 1 | 3 | 1/2/3 |
| 1 | 3 | 1/4/3 |
+---------+-----------+------+---------+
最佳答案
原文链接:https://www.f2er.com/mysql/532058.html