SQL: Select SUM of all children records recursively SQL: Select SUM of all children records recursively oracle oracle

SQL: Select SUM of all children records recursively


This may be some some assistance: http://mikehillyer.com/articles/managing-hierarchical-data-in-mysql/

This would be a simple query in Oracle ( http://download-east.oracle.com/docs/cd/B12037_01/server.101/b10759/queries003.htm) since it supports hierarchical queries using "CONNECT BY" but I don't think there's a comparable solution for MySQL. It looks like you're going to do something really inefficient or you're going to have to modify your table structure to support this specific function.


One solution would be to add a column to the table "topmost_parent" and join on that.


You should consider re-structuring the data using a nested set model. The following link describes how to do it:

http://www.vbmysql.com/articles/database-design/managing-hierarchical-data-in-mysql