sum price of childs in other table mysql

后端 未结 2 627
谎友^
谎友^ 2021-01-15 17:57

I have two table one store data child and parent hierarchy and other paths and descendant

+----------+------------+-----------+
| userid   |    parent  |             


        
2条回答
  •  旧巷少年郎
    2021-01-15 18:33

    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
    

提交回复
热议问题