I'm trying to do a running sum. Here's the query I have so far:
Here's the result set I get back:
The problem, as may be able to see, is that the running sum is the sum of an entire day, not the sum at the point of an individual transaction.
My problem is that I can't qualify f2.fin_id <= f.fin_id because the data set is ordered by the two date columns, making the ordering of the ID column useless. I can't use f2.fin_added <= f.fin_added because they weren't necessarily added in a linear order (notice the the tuxedo rental was added before the Price Chopper transaction).
Any ideas?
[ Edit: Holy crap, that's the last time I use MS Paint to make a JPEG ]
Code:
SELECT f.fin_id AS `id`, f.fin_text AS `What`, concat('$', f.fin_amt) AS `Amount`, DATE_FORMAT(f.fin_occur, '%m/%d/%Y') AS `Date`, f.fin_added, SUM(f2.fin_amt) as `Balance` FROM finances f, finances f2 WHERE f.fin_domain = 'CC' AND DATE_FORMAT(f.fin_occur, '%Y') = '2007' AND DATE_FORMAT(f.fin_occur, '%m') = '10' AND f2.fin_domain = 'CC' AND f2.fin_occur <= f.fin_occur GROUP BY f.fin_id ORDER BY f.fin_occur, f.fin_added
Here's the result set I get back:
The problem, as may be able to see, is that the running sum is the sum of an entire day, not the sum at the point of an individual transaction.
My problem is that I can't qualify f2.fin_id <= f.fin_id because the data set is ordered by the two date columns, making the ordering of the ID column useless. I can't use f2.fin_added <= f.fin_added because they weren't necessarily added in a linear order (notice the the tuxedo rental was added before the Price Chopper transaction).
Any ideas?
[ Edit: Holy crap, that's the last time I use MS Paint to make a JPEG ]
the idiot is the person who follows the idiot and your not following me your insulting me your following the path of a idiot so that makes you the idiot - LC Tusken