Re: Problem in getting running total with group by
Posted by:
Rick James
Date: February 08, 2014 12:06PM
* Don't use VARCHAR for dates and time.
* Use DATETIME, not VARCHAR
* Use a single column (of datatype DATETIME or TIMESTAMP) with both DATE and TIME, not two columns.
* Garbage in, garbage out: '09:60:10' -> '0.416782407'
1 01-01-2013 10:40:10 Entry 1 1 1
1 02-01-2013 09:30:10 Entry 1 2 1
(@runtot := a.flag + @runtot) AS rt, ( @runtot := a.flag ) ne
seems correct. Details:
1 01-01-2013 10:40:10 Entry 1 (@runtot := a.flag + @runtot)->1 @runtot := a.flag->1
That is, @runtot is set to 1 from arithmetic, then it is set to 1 from a.flag.
1 02-01-2013 09:30:10 Entry 1 (@runtot := a.flag + @runtot)->2 @runtot := a.flag->1
First @runtot := 1 + 1 = 2, then $runtot is set back to 1.
The rt column (1, then 2) seems correct as a "running total".
The rt column:
(@runtot := a.flag + @runtot)
could be simplified to just
a.flag + @runtot
Perhaps the problem is that you are counting a.flag twice? Once in the current line, then again as the initial value of @runtot?
Or, if you really mean "running total", you should get rid of the "ne" column, which resets @runtot.
Subject
Written By
Posted
February 06, 2014 05:42AM
February 06, 2014 03:03PM
February 07, 2014 03:16AM
Re: Problem in getting running total with group by
February 08, 2014 12:06PM
February 08, 2014 11:13PM
February 09, 2014 12:50AM
Sorry, you can't reply to this topic. It has been closed.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.