我得到了一个蜂巢表,如下所示:
Table A
docid corr_docid header
100 a
101 100 b
102 c
105 101 d
106 102 e
107 106 f
108 107 g
109 h
是否可以创建另一个表。
这里corr_docid 107 用 docid 107 更正文档。
表 B 如下:
Table A
docid corr_docid header newdocid
100 a 105
101 100 b 105
102 c 108
105 101 d 105
106 102 e 108
107 106 f 108
108 107 g 108
109 h 109
这在蜂巢中可能吗?
您可以尝试使用此本机 SQL 以获得所需的结果,仅当您知道层次结构深度/级别时,这才有效,此处为 4。
`select a.docid,
a.corr_docid,
case when b.docid is null then a.docid
when c.docid is null then b.docid
when d.docid is null then c.docid
else d.docid
end newdocid
from Table_A a left join Table_A b on a.docid = b.corr_docid
left join Table_A c on b.docid = c.corr_docid
left join Table_A d on c.docid = d.corr_docid ;`