I got two tables
org
// org_id // parent_id // org_name // mid //
1000 1 apple 1111
1001 1 google 2222
10000001 1000 unicooo 3333
10010001 1001 uber 4444
trans
// money // date // mid //
1000 2015-10-1 1111
201 2015-10-1 2222
201 2015-10-1 3333
1001 2015-10-1 4444
2000 2015-10-2 1111
201 2015-10-2 2222
201 2015-10-2 3333
1001 2015-10-2 4444
I join two table using mid and I want to get output like
// org_name // sum_money // date //
apple 1201 2015-10-1
apple 2201 2015-10-2
google 1202 2015-10-1
google 1202 2015-10-2
unicooo 201 2015-10-1
unicooo 201 2015-10-2
uber 1001 2015-10-1
uber 1001 2015-10-2
for example
// org_name // sum_money // date //
apple 1201 2015-10-1
apple got 1000 in 10-1 and unicooo which its parent_id is apple's id got 201 in 10-1, so apple got 1201 on 10-1.And even apple and its 'child' got zero on 10-1, I still want to display it,and set sum_money to zero.
I tried
select sum(a.money) from trans a right join
(select b.mid from org b where b.parend_id = '1') as c
on a.mid = c.mid group by a.date
luckily, I got what I want for 'apple',but I want to select all column,but don't know how to do with it.Two or more sql query are also welcome.