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

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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.