As far as I know Clickhouse doesn't support recursive CTEs, so I'd like to rewrite a query that I'm using on SQL Server. Below there's the snippet :)
WITH cte
(ID, ID_PARENT, OBJ_DESC, CHILD, PARENT, CLASS_NAME, CATEGORY_NAME, LEVEL)
AS (
select a1.STC_SQLIDENTITY, a2.ID, a1.OBJ_DESC, a1.CHILD, a1.PARENT, a1.CLASS_NAME, a1.CATEGORY_NAME, 4 as LEVEL from treeOne as a1
join treeTwo as a2
on a2.CHILD = a1.PARENT
where PARENT in
(select distinct PARENT from alberatura where PARENT not in (select CHILD from treeOne))
union all
select a2.SQLIDENTITY, itms.ID, a2.OBJ_DESC, a2.CHILD, a2.PARENT, a2.CLASS_NAME, a2.CATEGORY_NAME, itms.LEVEL+1 as LEVEL from treeOne a2
INNER JOIN cte itms ON itms.CHILD = a2.PARENT
)
SELECT * FROM cte;
Do you think that Clickhouse is efficient to do such operations?
Thanks a lot!