Can someone let me know if you can obtain the following data request completed in 1 SQL statement:

if possess a table A that referred to a tree structure with fields

A_id, A_parent_id

i in addition have a table B that consists of some interesting data (statistical)

B_id, B_value

the records within this table B might have nodes within the tree connected into it (via table C)

C_id, A_id, B_id

Now i require the following request. The input is n nodes within the tree A, per the id's:
A_id1, A_id2, ..., A_idn

Let's focus on the i-th child node (say with id 'child_id_i') of A_idn (within the tree referred to with a) I wish to return the sum of B_value's that the related record in B has all of the nodes A_id1, ..., A_id(n-1), and a_child_i connected by using it. Say this sum is sum_i, i quickly want back the next array:

sum_0, child_id_0,
sum_1, child_id_1,
...
sim_k, child_id_k

where k is the amount of children (not grandchildren etc) of A_idn. I really hope someone might help me!

EDIT: It switched out the problem was slightly different for the reason that the area value wasn't an immediate area on the table B but it was saved inside a different table. Here's the entire problem. I've got a database with records having a variable quantity of fields. So fields aren't saved in rows, but rather each area is its very own table having a mention of the an archive ID. This info have a area known as "Value" that is saved within the table B and they've a area "Tree-node" (that may occur multiple occasions) within the table C. Each Tree-node area connected to some single record holds just one A_id in the table A. So an archive has connected by using it something and many nodes in the tree. More formally,

Table A : { A_id, A_parent_id }      
// describes tree structure
Table B : { B_record_id, B_value }   
// value associated to the record given by B_record_id
Table C : { B_record_id, B_A_id }     
// tree node with id B_A_id associated to record B_record_id

The input is id_1, id_2, ..., id_n

For every child of id_n, say child_id_i I wish to sum B_value total records (record_id) which have id_1, id_2, ..., child_id_i connected to that particular record_id. Permit this to value be V_i

Output ought to be the following 2-dimensional array: ((child_id_1, V_1), ..., (child_id_n, V_n))

Thanks.

EDIT: I wound up fixing it with a couple PHP logic. I do not think you can do that in one query.