"Dmitry Lendel" ...
Только вот зачем так писать ? Чтобы никто не смог это потом читать ?
Я не знаю ни одной причины вкладывать WITH в подзапрос, его всегда можно
определить *до* основного запроса...
Идея была по входному параметру отображать список
0 по текущей группе
1 по вложенным
2 все
А что ты прелагаешь?
А я должен что-то предложить ? Ну, держи :)
WITH RECURSIVE
R_TREE AS
(
SELECT A.IDKEY
FROM stuff_groups A
WHERE A.IDKey=:LIDKey and (cast(?IDViewType as integer)=1)
UNION ALL
SELECT B.IDKEY
FROM stuff_groups B
inner join R_TREE A on B.IDPARENT = A.IDKEY and B.IDPARENT <> B.IDKey
),
B as
(
Select GS.IDKey
from stuff_groups GS
where (cast(?IDViewType as integer)=0) and GS.idkey=?IDKey
union all
Select IDKey from R_Tree
union all
Select GS.IDKey
from stuff_groups GS
where (cast(?IDViewType as integer)=2) and
not exists(Select GS1.IDKey
from Stuff_Groups GS1
where GS1.IDParent=GS.IDKey and GS1.IDKey<>GS1.IDParent)
)
select A.*
From stuff_list A inner join B on b.IDKey=A.idgroups
--
Хорсун Влад