dbTalk Databases Forums  

Running Totals with MySQL

mailing.database.mysql-plusplus mailing.database.mysql-plusplus


Discuss Running Totals with MySQL in the mailing.database.mysql-plusplus forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Kerry Frater
 
Posts: n/a

Default Running Totals with MySQL - 11-21-2006 , 01:32 AM






I need to keep a running total (not an aggregate) based on data in two
columns e.g.
a b calculated_col
100 -10 90
50 10 150
-10 -20 120

the rows are selected on certain WHERE criteria and so the running total is
not fixed data. The running total is for display on the screen.
Doing this work in the language interfacing with MySQL is causing some odd
side effects so I was hoping to do the work on the MySQL side instead.

Kerry


--
MySQL++ Mailing List
For list archives: http://lists.mysql.com/plusplus
To unsubscribe: http://lists.mysql.com/plusplus?unsu...ie.nctu.edu.tw


Reply With Quote
  #2  
Old   
Kerry Frater
 
Posts: n/a

Default RE: Running Totals with MySQL - 11-21-2006 , 09:27 AM






I have come across and modified a nice little solution to this with a big
BUT. The code works out to be

select @runbal:=@runbal+modamount1+(modamount2 * -1) as runbal, t.*
from (select @runbal:=0) rt,mytable t
where myref='Ref1'
order by date,uniqueref

This gives me the running total results I want except that I use Delphi with
MicroOlap's DAC to interface with MySQL and their TMySQLQuery doesn't
support this construct.
MicroOlap tell me that it will work in the next release.

Can someone give me another way to do the same thing without the use of
variables?

My attempts so far have failed miserably

Kerry



-----Original Message-----
From: Kerry Frater [mailto:kerry (AT) myforefathers (DOT) co.uk]
Sent: 21 November 2006 07:31
To: plusplus (AT) lists (DOT) mysql.com
Subject: Running Totals with MySQL


I need to keep a running total (not an aggregate) based on data in two
columns e.g.
a b calculated_col
100 -10 90
50 10 150
-10 -20 120

the rows are selected on certain WHERE criteria and so the running total is
not fixed data. The running total is for display on the screen.
Doing this work in the language interfacing with MySQL is causing some odd
side effects so I was hoping to do the work on the MySQL side instead.

Kerry


--
MySQL++ Mailing List
For list archives: http://lists.mysql.com/plusplus
To unsubscribe:
http://lists.mysql.com/plusplus?unsu...rs (DOT) co.uk


--
MySQL++ Mailing List
For list archives: http://lists.mysql.com/plusplus
To unsubscribe: http://lists.mysql.com/plusplus?unsu...ie.nctu.edu.tw


Reply With Quote
  #3  
Old   
Warren Young
 
Posts: n/a

Default Re: Running Totals with MySQL - 11-21-2006 , 06:06 PM



Kerry Frater wrote:
Quote:
I need to keep a running total (not an aggregate) based on data in two
columns
This list is for discussions about MySQL++, the C++ wrapper for MySQL's
C API. This question is about MySQL itself, so please take it up on the
main MySQL mailing list.

--
MySQL++ Mailing List
For list archives: http://lists.mysql.com/plusplus
To unsubscribe: http://lists.mysql.com/plusplus?unsu...ie.nctu.edu.tw



Reply With Quote
  #4  
Old   
Kerry Frater
 
Posts: n/a

Default RE: Running Totals with MySQL - 11-28-2006 , 01:08 PM



Whoops


-----Original Message-----
From: Warren Young [mailto:mysqlpp (AT) etr-usa (DOT) com]
Sent: 22 November 2006 00:07
To: MySQL++ Mailing List
Subject: Re: Running Totals with MySQL


Kerry Frater wrote:
Quote:
I need to keep a running total (not an aggregate) based on data in two
columns
This list is for discussions about MySQL++, the C++ wrapper for MySQL's
C API. This question is about MySQL itself, so please take it up on the
main MySQL mailing list.

--
MySQL++ Mailing List
For list archives: http://lists.mysql.com/plusplus
To unsubscribe:
http://lists.mysql.com/plusplus?unsu...rs (DOT) co.uk


--
MySQL++ Mailing List
For list archives: http://lists.mysql.com/plusplus
To unsubscribe: http://lists.mysql.com/plusplus?unsu...ie.nctu.edu.tw



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.