I have a table of organizations. The columns are: id int, name text, parent_id int.so it has a tree structure. I have another table, staff, with the fields id int, name txt, family txt, organization_id int. I have another table, clock, and the columns are: id int, staff_id int, Date date, Time time, which registers the clock in and clock outs.
For each organization in the tree (for each node) i want to calculate the working hours of its personnel. Finally i should sum up the working hours of children to get the working hours of its parent and so on.
So i need a function to do that. Can sb help?