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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query help

Status
Not open for further replies.

rotelmak

Programmer
Nov 29, 2004
31
0
0
MK
My test table have this columns with this data

cus_id inv_n date_ip debit credit
1 101 10.01.07 100.00
1 101 25.01.07 70.00
1 101 26.01.07 10.00

2 102 11.01.07 200.00
2 102 26.01.07 150.00
2 103 27.01.07 300.00

How can I got with query this resulsts

cus_id inv_n date_ip debit credit total
1 101 10.01.07 100.00 100.00
1 101 25.01.07 70.00 30.00
1 101 26.01.07 10.00 20.00

2 102 11.01.07 200.00 200.00
2 102 26.01.07 150.00 50.00
2 103 27.01.07 300.00 350.00
 
This for me looks like more of an applicaation-level problem, as opposed to a database level problem, though it could be done. It is more of an end-total that the following gives you.

The select would contain (pseudocode)
(sum(debit) - sum(credit)) as balance group by cus_id

(Though I think it's the wrong way around, subtract debits from credits, to give you your balance)

At least that's how I'd do it, anything more I'd put at the application level.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top