Сергей Asked:2020-06-29 15:41:25 +0800 CST2020-06-29 15:41:25 +0800 CST 2020-06-29 15:41:25 +0800 CST 计算树中字段的总和 772 有一个表有 id(int), name(text), parent(int) 和 value(int) 字段,如何计算我自己和所有孩子的价值总和?通过mysql或输出嵌套数组树并以某种方式在内部递归计数? php 1 个回答 Voted Best Answer Grulex 2020-06-29T16:15:48+08:002020-06-29T16:15:48+08:00 SELECT t1.id, t1.name, (t1.value + SUM(t2.value)) AS sum FROM table AS t1 LEFT JOIN table AS t2 ON t2.parent = t1.id GROUP BY t1.id
1 个回答