hi to all
I want to sum different field came from table table. Here is the illustration.
Any help would greatly appreciated
Thanks in advance
Tirso
maintable
id : name : firstname : date_created
1 : john : ko : 2010/01/12
2 : mhel : sy : 2010/01/15
3 : johnson : king : 2010/01/16
4 : venedict : lee : 2010/01/17
5 : rafael : wanglu : 2010/01/18
(table1.info_id related with maintable.id)
table1
id : info_id
1 : 1
2 : 2
3 : 2
4 : 3
5 : 4
6 : 5
(table2.rec_id related with table1.id)
table2
id : rec_id : code_debit : act_code : debitval : cashflow_activities
1 : 1 : 101 : cash_others : 200 : operating
2 : 2 : 103 : cash_mbtc : 100 : operating
3 : 3 : 103 : cash_mbtc : 500 : operating
4 : 4 : 105 : cash_peso : 250 :
5 : 5 : 105 : cash_peso : 175 :
6 : 6 : 105 : cash_peso : 350 :
(table3.rec_id related with table1.id)
table3
id : rec_id : code_credit : cash_code : creditval : cashflow_activities
1 : 1 : 101 : cash_others : 200 :
2 : 2 : 104 : cash_peso : 100 :
3 : 3 : 105 : cash_peso : 500 :
4 : 4 : 101 : cash_others : 300 : operating
5 : 5 : 106 : receivables : 600 : operating
6 : 6 : 103 : cash_mbtc : 700 : operating
I want to get the sum of debitval with the same act_code plus the sum of creditval with the same cash_code in which act_code = cash_code and cashflow_activities = ‘operating’ and maintable.date_created between ‘fromdate’ AND ‘todate’
table result
num_code : act_code : total
101 : cash_others : 500
103 : cash_mbtc : 1300
106 : receivables : 600