Right now I have a dataset like this; (8 records)
cid pid
108 100
108 100
423 400
423 400
100 0
100 0
100 0
200 0
the tree like as follows:
root -- 0
--child 100
--sub child 108
---sub ...(maybe has more level)
--child 200
--sub child 205
--child 400
--sub child 423
And I want to count all sum records each by ever child (not sub child, sub child's record should calculate into it's father or grandfather until the first level child node).
so the result should like:
node counts
100 5
200 1
400 2
But when I use start with connect by and with group by keywords I cannot get the expected result.
my sql is as follows:
select cid as node,count(1) as counts
from (one subselect for get the 8 records) a
start with a.pid = '0'
connect by prior a.cid = a.pid) t group by cid;
result is empty.. who can help me? or who knows the detail for the oracle group by keywords works when used together with a tree structure?