我正在查询一些data (SQL, presto),,每个项目都可以是另一个项目的父项或子项。parent IDs和child IDs作为数组存储在该主ID的行中(Bigint)。每个任务都可以是多个父母的孩子。
它看起来像是:
id | parent_ids | child_ids
1 | [3] | []
2 | [3] | []
3 | [] | [2,1]
4 | [] | [5]
5 | [4, 6] | []
6 | [] | [5]我需要一个包含所有parent Ids和每个children的列表,作为该父程序的附加行:
id | child
3 | 1
3 | 2
4 | 5
6 | 5知道我怎么能做到这一点吗?
发布于 2020-09-11 16:59:23
我想你想:
select p.parent_id as id, t.id as child_id
from t cross join
unnest(t.parent_ids) p(parent_id)https://stackoverflow.com/questions/63851317
复制相似问题