Try getting the sum of debit, credit individually in the form of inline view and then try to include them in a single select (from respective inline views). [ June 22, 2007: Message edited by: Raghavan Muthu ]
Edisandro Bessa
Ranch Hand
Joined: Jan 19, 2006
Posts: 584
posted
0
The SQL below works for both Sybase and MySQL versions.
If you use another database just change it according to your needs.
[ June 22, 2007: Message edited by: Edisandro Bessa ]
"If someone asks you to do something you don't know how to, don't tell I don't know, tell I can learn instead." - Myself
Julien Martin
Ranch Hand
Joined: Apr 24, 2004
Posts: 383
posted
0
Thanks Edisandro,
I adapted your query as follows so that it work with DB2:
which gives me this:
whereas I would like this:
Any idea what I am missing?
Julien.
Julien Martin
Ranch Hand
Joined: Apr 24, 2004
Posts: 383
posted
0
I found the solution:
select sum(sum_debit) as tot_debit, sum(sum_credit) as tot_credit, client from (select (case debit_credit when 'd' then sum(amount) else 0 end ) as sum_debit, (case debit_credit when 'c' then sum(amount) else 0 end ) as sum_credit, client from test group by client, debit_credit) as t group by client