Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Summarising 2 Records into 1 1

Status
Not open for further replies.

TimboA

MIS
Jul 12, 2001
38
GB
I have a query which looks something like this :-

select acct_no, type, sum(amount) TOTAL
from table1
group by acct_no, type;

The results look like this :-

ACCT_NO TYPE TOTAL

123456 DEBITS -2500
123456 CREDITS 4000

What I really want is this :-

ACCT_NO DEBIT TOTAL CREDIT TOTAL ACCOUNT BAL

123456 -2500 4000 1500

Can anyone help me with the syntax for this please ??

Thanks in advance.
 
Use DECODE function like,

SELECT ACC_CODE,SUM(DECODE(TYPE,'DEBIT',AMOUNT,0)) DEBIT_TOT,SUM(DECODE(TYPE,'CREDIT',AMOUNT,0)) CREDIT_TOT
FROM T1
GROUP BY ACC_CODE
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top