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 db.Country = mycountries.ID
WHERE ...
GROUP BY db.Country;
HTH,
Dusan
C.R.Vegelin napsal(a):
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`
FROM data2006 AS db
LEFT JOIN mycountries ON db.Country = mycountries.ID
WHERE ...
GROUP BY db.Country;
Results are:
Row Country Q1 RunSum
1 Germany 90 90
2 France 60 60
3 Norway 24 24
etc.
I expect the RunSum for Germany 60, France 150, Norway 174 etc.
Whay am I doing wrong ? Any help is appreciated !
Regards, Cor
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]