I have two table one store data child and parent hierarchy and other paths and descendant
+----------+------------+-----------+ | userid | parent |
try this
select sum(b.price) from webineh_prefix_nodes_paths_tmp a join webineh_prefix_nodes_tmp b on (b.userid = a.descendant_id) where a.ancestor_id in ( 1,2,3) GROUP by ancestor_id