title: postgresql count the number of children
body: <p>The tree is unlimited depth. example:</p>
  
  <pre><code>+----+-------+--------------------+
  | id | name  | parent_id |  value |
  +----+-------+--------------------+
  |  1 | test1 |           |    0   |
  |  2 | test2 |     1     |    0   |
  |  3 | test3 |     2     |    5   |
  |  4 | test4 |     1     |    0   |
  |  5 | test5 |     4     |    5   |
  |  6 | test6 |     4     |    0   |
  |  7 | test7 |     6     |    10  |
  +----+-------+--------------------+
  </code></pre>
  
  <p>I want to get the total value of one's children.
  just like this:</p>
  
  <pre><code>+----+-------+--------------------+
  | id | name  | parent_id |  value |
  +----+-------+--------------------+
  |  1 | test1 |           |    20  |  =  test2.value + test4.value
  |  2 | test2 |     1     |    5   |  =  test3.value
  |  3 | test3 |     2     |    5   |  
  |  4 | test4 |     1     |    15  |  =  test5.value + test6.value
  |  5 | test5 |     4     |    5   |
  |  6 | test6 |     4     |    10  |  =  test7.value
  |  7 | test7 |     6     |    10  |
  +----+-------+--------------------+
  </code></pre>
  
  <p>any suggestion ? Thanks!</p>