The left/right fields seem to be for nested sets, right? Something
like this will work:
SELECT MAX(c)
FROM (
SELECT COUNT(t2.title) as c
FROM fruit t1
INNER JOIN fruit t2 where t2.left <= t1.left and t2.right >= t1.right
GROUP BY t1.id
) t
On another note, there's no need to record the parent field in the
table, it's computable from the left/right values, and is an instance
of [potentially troublesome] denomalization.
cheers,
barneyb
On 7/10/05, Jeff Chastain <[EMAIL PROTECTED]> wrote:
> I have a hierarchical set of data stored in tree format. The tree may or
> may not be a binary tree ... i.e. each node could have 0 thru N sub-nodes.
> Now, I need to calculate the length of the longest branch, or otherwise, the
> depth of the tree. My comp. sci. days are a long way behind me, so does
> anybody know how this would be calculated? An example tree I have been
> working with is as follows ...
>
> +--------+--------+------+-------+
> | parent | title | left | right |
> +--------+--------+------+-------+
> | | Food | 1 | 18 |
> | Food | Fruit | 2 | 11 |
> | Fruit | Red | 3 | 6 |
> | Red | Cherry | 4 | 5 |
> | Fruit | Yellow | 7 | 10 |
> | Yellow | Banana | 8 | 9 |
> | Food | Meat | 12 | 17 |
> | Meat | Beef | 13 | 14 |
> | Meat | Pork | 15 | 16 |
> +--------+--------+------+-------+
>
> So, in this case, the depth would end up being 4 ... Food, Fruit, Red,
> Cherry - or - Food, Fruit, Yellow, Banana.
>
> Any ideas?
>
> Thanks
> -- Jeff
>
--
Barney Boisvert
[EMAIL PROTECTED]
360.319.6145
http://www.barneyb.com/
Got Gmail? I have 50 invites.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Logware (www.logware.us): a new and convenient web-based time tracking
application. Start tracking and documenting hours spent on a project or with a
client with Logware today. Try it for free with a 15 day trial account.
http://www.houseoffusion.com/banners/view.cfm?bannerid=67
Message: http://www.houseoffusion.com/lists.cfm/link=i:4:211515
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54