Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.tools -> connect by and aggregate functions

connect by and aggregate functions

From: Mike Linksvayer <ml_at_gondwanaland.com>
Date: 4 Dec 2000 20:49:57 GMT
Message-ID: <90h01l$2oit$1@nntp1.ba.best.com>

Say I have some hierarchical data like

SQL> select * from hdata;

      ITEM TARGET VALUE
---------- ---------- ----------

         0                     0
         1          0          5
         2          1          7
         3          0         12
         4          1          9
         5          3          2

The first is a dummy row to allow getting all roots with 'start with item = 0' as 'start with item = null' doesn't work.

I can reproduce a tree with a query like

column item format a10;
select lpad(' ',level)||item item, target, value from hdata connect by prior item = target start with target = 0;

ITEM           TARGET      VALUE        sum       avg
---------- ---------- ----------        imaginary imaginary
 1                  0          5        21         7
  2                 1          7         7         7
  4                 1          9         9         9
 3                  0         12        16         8
  5                 3          4         4         4
 

I'd like to be able to to obtain sums, averages and the like for all nodes in a subtree, as in the imaginary results above. I'd also like to be able to sort nodes within a subtree by some value calculated from a node and its children.

I could do this by executing the above query, reading it into my own data structures and doing the tree aggregate calculations and sorting there. Doesn't seem very efficient.

Any hints or recommendations on how to proceed?

The 'value' above is actually a score from an intermedia text search, so it won't help to precalculate anything, as all values will change with the text query.

Thanks...
Mike

--
                                       See From: and Organization: above.
Received on Mon Dec 04 2000 - 14:49:57 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US