может кому пригодится... вот что получилось:
Код:
SELECT basedoctype, baseid, doctype,
LTRIM (SYS_CONNECT_BY_PATH (ID, ', '), ',') AS pn
FROM (SELECT b.basedoctype, b.baseid, b.doctype, b.ID,
ROW_NUMBER () OVER (PARTITION BY b.baseid ORDER BY b.ID)
AS n,
COUNT (*) OVER (PARTITION BY b.baseid ORDER BY b.ID ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING)
AS cnt
FROM supermag.smcommonbases b
WHERE b.doctype = 'WI'
AND b.basedoctype = 'OR'
AND b.baseid IN (
SELECT a.ID
FROM supermag.smdocuments a
WHERE a.doctype = 'OR'
AND a.createdat BETWEEN TO_DATE ('08.11.2010',
'DD.MM.YYYY'
)
AND TO_DATE ('14.11.2010',
'DD.MM.YYYY'
)
AND a.clientindex = '1490'))
WHERE n = cnt
START WITH n = 1
CONNECT BY n = PRIOR n + 1 AND baseid = PRIOR baseid;
Результат:
OR ЗПП03013255 WI ПНП03009414
OR ЗПЦП001790 WI ПНП10005458, ПНП10005459
OR ЗПЦП001791 WI ПНП06010597, ПНП06010687
OR ЗПЦП001792 WI ПНП02003571
OR ЗПЦП001793 WI ПНП05008740, ПНП05008819
OR ЗПЦП001794 WI ПНП01011707, ПНП01011782
OR ЗПЦП001795 WI ПНП08008754
OR ЗПЦП001796 WI ПНП04009402