I want a query in which data is grouped by reseller_id
where parent_res_id = 0
. All other rows shall use the parent_res_id
instead of reseller_id
.
For example, parent_res_id
0 (admin account) spawned two reseller_id
: 1 and 2. Each of them created another reseller (3 and 4 respectively). I want to group rows of the children with their parents, so rows of reseller_id
3 are added to 1 and rows of reseller_id
4 are added to 2. Basically it's a tree of depth 1.
Table:
duration call_charge reseller_id parent_res_id
2 1 1 0
3 2 2 0
4 3 3 1
5 4 4 2
6 5 5 1
7 6 6 5
Desired result:
sum(duration) sum(call_charege) reseller_id
19 15 1
8 6 2