I would like to SUM two fileds from different rows from the same table but I don't know how to do that.

E.g.

BillingTransactionsIndex CreateDate UserType UserIndex TransType Reference Total Balance
2 6/5/2008 15:02 1 51 1 150 -288.2 -288.2
5 6/8/2008 11:55 1 51 1 157 -1.58674 -289.787

In the table above I want SUM fields Total and Balance for the first row and the the next row SUM 2nd row Total with 1st row Balance

Please help

Thanks

Recommended Answers

All 2 Replies

I want this

Total Balance
row 1 90 90
row 2 23 113
row 3 15 128
row 4 20 148

In row 2 to get the balance I SUM Balance(90) of row 1 with Total(23) of row 2 to get Balance (113) of row 2. Same thing is done for the next row by adding with Balance of previous row

Hi tkotey

Similar problem we have discussed on http://www.daniweb.com/forums/thread127644.html.
you may investigate SQL code from posts #5 and #7 where I gave solutions on how to compute balance values from consecutive rows. You can adapt that code so it fits your specific requirements. If you have further problems we can discuss them here.

krs,
tesu

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.