0

I've a table named [transaction]

idtransaction is my primary key

---------------- [transaction] -------------------------
idtransaction | customerID | amount | transDate

Amount is the credit or debit / they differ when amount < 0 it is credit and when amount > 0 it's debit

Sample Data
idtransaction | customerID | amount | transDate
1 | Cust001 | 200 | 12/03/07
2 | Cust001 | 200 | 12/04/07
3 | Cust001 | -100 | 12/13/07
4 | Cust001 | 500 | 12/23/07

I need to query like this: where customerID = cus001
balance = debit - credit , but for every row the it add the previous balance.


idtransaction | customerID | debit | credit | balance | transDate
1 | Cust001 | 200 | 0 | 200 | 12/03/07
2 | Cust001 | 200 | 0 | 400 | 12/04/07
3 | Cust001 | | 100 | 300 | 12/13/07

thx in advance

2
Contributors
2
Replies
3
Views
9 Years
Discussion Span
Last Post by itanacious
0

select idtransaction, customerID,debit, credit, (debit - credit) as balance, transDate from transaction where customerID='Cust001' ? Is that what you are talking about ?

0

nav33n nope dude,
I've come across with this Oracle Queries

sum(amount) over (order by idtransaction

, i've just dont know how analytic function could be implemented in MySql special the OVER() function or AKA Ranking function

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.