如何解决如何将sql递归转换为javascript
当我尝试从有向图中的顶点搜索可能的路径时。我有一个 SQL 递归来做到这一点。但是,我不想使用数据库,因此想将 SQL 递归转换为没有 SQL 查询的节点 js 递归函数,但我无法弄清楚。 我该怎么做?这是我的 SQL 递归
drop table edges;
create table edges (route_id integer,stuff_id integer,option_id integer);
insert into edges (route_id,stuff_id,option_id) values (36,73,75);
insert into edges (route_id,option_id) values (37,74);
insert into edges (route_id,option_id) values (38,88);
insert into edges (route_id,option_id) values (39,82,73);
WITH RECURSIVE search_path (depth,option_tree) AS (
SELECT 1,ARRAY[e.stuff_id]
FROM edges e
UNION ALL
SELECT f.depth + 1,option_tree || d.option_id
FROM edges d,search_path f
WHERE f.option_tree[array_length(option_tree,1)] = d.stuff_id
)
SELECT * FROM search_path
WHERE option_tree[1] = 82
ORDER BY depth DESC;
我们可以通过 https://extendsclass.com/postgresql-online.html
测试 SQL版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。