0

我使用 postgres ltree 插件对树数据结构进行建模,有以下数据集:

在此处输入图像描述

此查询允许我在切割下方切割返回节点的树:

with data(path) as (SELECT * FROM test WHERE yaxis >= 2 ORDER BY yaxis) select * from data d1 where not exists (select 1 from data d2 where d1.path <> d2.path and d1.path @> d2.path);

在此处输入图像描述

注意,其中一个节点不是叶子,我想从上面获取结果,并获取叶子并返回聚合的数据集。这是我想使用的第二个查询:

SELECT * FROM test WHERE path <@ 'Top.Collections.Pictures.Astronomy' and leaf = true;

请注意,上面的“Top.Collections.Pictures.Astronomy”是从第一个查询输入的。

第二个查询返回这个集合:

在此处输入图像描述

我希望看到的组合结果是用第二个查询中的子代替换“Top.Collections.Pictures.Astronomy”

4

0 回答 0