tags:

views:

58

answers:

0

hi to all

I want to sum different field came from table table. Here is 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
(table1.info_id related with maintable.id)
id  info_id
1   1
2   2
3   2
4   3
5   4
6   5


table2
(table2.rec_id related with table1.id)
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
(table3.rec_id related with table1.id)
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


table result
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' 
num_code        act_code        total
101             cash_others     500
103             cash_mbtc       1300
106             receivables     600