Re: Quote of the Week
Date: 19 May 2004 09:33:05 -0700
Message-ID: <18c7b3c2.0405190833.29fa8269_at_posting.google.com>
>> [How would you compare two of these organization structure
relations for equality?] Aggregated total? <<
I never thought of that! I feel like an idiot! Why do you keep coming up with good ideas after the book is printed??
But there is no need for recursion to sum the subtrees:
SELECT O2.emp, SUM(S1.weight)
FROM OrgChart AS O1, OrgChart AS O2,
Salaries AS S1
WHERE O1.lft BETWEEN O2.lft AND O2.rgt
AND O1.emp = S1.emp
GROUP BY O2.emp;
>> Finally, tree structure are identical if they have identical weight
at the root. <<
Not true; consider the set of weights (1,2,3,4)= 10 which could be split up as ((1,4), (2,3))= 10 or ((1,2,3),(4)) = 10. What we need is two tables with the sums from the trees which are identical, weight for weight. Easy enough:
((<<above query for Table A>>) EXCEPT ((<<above query for Table B>>) IS NULL Received on Wed May 19 2004 - 18:33:05 CEST