sql - Calculate a running total in MySQL -
I have this MySQL query:
SELECT DAYOFYEAR (`date`) ASD , COUNT (*) `from commands' where` haspad` & gt; 0 by group D which gives something like this:
D | COUNT (*) | 20 | 5 | 21 | 7 | 22 | 12 | 23 4 | To show the running total, I'll end up with one more column:
d | COUNT (*) | ??? | 20 | 5 | 5 | 21 | 7 | 12 | 22 | 12 | 24 | 23 4 | 28 | Is this possible?
Maybe a simple solution for you and prevents the database from doing a ton of questions. Performs the query, then there is a little math on results in a single pass.
SET @runtot: = 0; SELECT q1.d, q1.c, (@runtot: = @runtot + q1.c) AS RT FM (Select Detroit (`date`) ASD, COUNT (*) AC-C`order` Where` Hepad & GT ; D Order D by Group 0) AS Q1 This will give you an additional RT (running total) column. Do not miss the sit statement located at the top or you will get a column of zero values to start running the total variable.
Comments
Post a Comment