SQL beginner need help

Hello,

I have to deal with a single table which is as follows:

amountdebit/creditclient

30dA

40cA

20dB

10cB

5cB

2dA

I want to end up with this:

debitcreditclient

3240A

2015B

Basically what I have done is asum on the amounts of the same kind (d/c) and agroup by on the client.

I have no idea on what SQL could produce the above result.

Can anyone help?

Thanks in advance,

Julien.

[504 byte] By [balteoa] at [2007-11-27 8:31:49]
# 1
select sum(if(debit_credit='d',amount,0)) as sum_debit, sum(if(debit_credit='c',amount,0)) as sum_credit, clientfrom testgroup by client
balteoa at 2007-7-12 20:27:27 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 2

Depends on your DBMS.

All ANSI compliant ones will probably be able to execute this:

select a.debit, b.credit, a.client from (

(select sum(amount) as debit, client from test where debit/credit = 'd' group by client) a

full outer join

(select sum(amount) as credit, client from test where debit/credit = 'c' group by client) b

on a.client = b.client

)

dwga at 2007-7-12 20:27:27 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...