Thanks John, I found a website that explains what I wanted to do - http://www.databasejournal.com/features/mssql/article.php/3112381/SQL-Server-Calculating-Running-Totals-Subtotals-and-Grand-Total-Without-a-Cursor.htm
I had never heard of rollup, it look really interesting, I will try it out and see what I can do with it. Cheers Mick On Mon, 2010-08-09 at 19:46 -0700, John Magee wrote: > > > On Aug 9, 2010, at 2:41 PM, Mick Sulley wrote: > > > Hi, > > > > I have a database with transaction data, transactions are basically > cash > > and assets, so cash in/out (positive or negative) and asset purchase > or > > sale (positive or negative). > > > > I would like to display a table showing the transactions and the > running > > total. How can I do that? > > > > I am not sure whether to try to do it in SQL and just display the > result > > using PHP or to use SQL to retrieve the transactions and calculate > the > > running total in PHP. > > > > Any help would be much appreciated > > > > Thanks > > > > Mick > You want to do it in mysql - it's just more useful in such a > situation. Do you know what roll ups are? > > Or do you just want to run one select query that has all the > transactions and then union it with a query that has the total. > > A running total gives a total after every transaction, if that's what > you want use roll up > >