我必须以pgsql查询的树格式显示输出
WITH RECURSIVE SYSTEM_PARTS("PART","PART_NUM","NODE_ID","PARENT_ID")
AS
(
select p."PART",p."PART_NUM",hd."NODE_ID",hd."PARENT_ID" from relma_hierarchy_data hd
INNER JOIN relma_part p on p."PART_NUM"=hd."FK_ID"
where hd."HIERARCHY_ID"=2 and hd."NODE_ID"=16515 and hd."PARENT_ID"=hd."NODE_ID"
UNION
select p."PART",p."PART_NUM",hd."NODE_ID",hd."PARENT_ID" from relma_hierarchy_data hd
INNER JOIN relma_part p on p."PART_NUM"=hd."FK_ID"
, SYSTEM_PARTS sp
where hd."HIERARCHY_ID"=2 and sp."NODE_ID"=hd."PARENT_ID" AND hd."NODE_ID"<>hd."PARENT_ID"
)
select * from SYSTEM_PARTS');
答案 0 :(得分:0)
1)如果这是LOINC数据,那么树的根的NODE_ID = PARENT_ID。
2)此外,树的PATH_ENUMERATION(&#39;杜威十进制数&#39;)可以帮助显示问题(如002.014.003是002.014的第三个孩子)。