I want to calc a running sum with @variables.
Using the command line client, I enter:
SET @row := 0, @runsum := 0;
followed by:
SELECT @row := @row+1 AS `Row`, mycountries.Name AS `Country`
, ROUND(SUM(db.Jan+db.Feb+db.Mar)) AS `Q1`
, @runsum := @runsum + SUM(db.Jan+db.Feb+db.Mar) AS `RunSum`
i suppose this to be working when you leave the group by?
On 2/6/07, C.R.Vegelin [EMAIL PROTECTED] wrote:
I want to calc a running sum with @variables.
Using the command line client, I enter:
SET @row := 0, @runsum := 0;
followed by:
SELECT @row := @row+1 AS `Row`, mycountries.Name AS `Country`
try to put parenthesis around @runsum := @runsum +
SUM(db.Jan+db.Feb+db.Mar)
SELECT @row := @row+1 AS `Row`, mycountries.Name AS `Country`
, ROUND(SUM(db.Jan+db.Feb+db.Mar)) AS `Q1`
, (@runsum := @runsum + SUM(db.Jan+db.Feb+db.Mar)) AS `RunSum`
FROM data2006 AS db
LEFT JOIN mycountries ON
oops, sorry, forget the last post i made. it's not related to the
group by. it should work like that from my point of view. a stripped
down version of this works for me (tried without the left join)
On 2/6/07, Lars Schwarz [EMAIL PROTECTED] wrote:
i suppose this to be working when you leave the
- Original Message -
From: Lars Schwarz [EMAIL PROTECTED]
To: mysql@lists.mysql.com
Sent: Tuesday, February 06, 2007 12:58 PM
Subject: Re: running sum with a @variable
oops, sorry, forget the last post i made. it's not related to the
group by. it should work like that from my point of view
, February 06, 2007 9:45 AM
Subject: Re: running sum with a @variable
Thanks Lars, Dusan,
I found out that the problem is caused by an ORDER BY clause,
left out in my example because I had no idea this would be the problem.
It works fine with LEFT JOIN and GROUP BY.
However, I need the ORDER