
Originally Posted by
K. Wolfe
I feel like I'd have to do a subquery to find the sum for that project where the pledge date <= each date in the range.
yeah, you could, but subqueries are occasionally very poor performers
i prefer a theta self-join
first, create this view --
Code:
CREATE VIEW pledges_by_date AS
SELECT pledge_date
, SUM(pledge_amt) AS pledge_sum
FROM pledges
GROUP
BY pledge_date
then, here's your cumulative query --
Code:
SELECT two.pledge_date
, SUM(one.pledge_sum) AS pledge_cumulative
FROM pledges_by_date AS two
LEFT OUTER
JOIN pledges_by_date AS one
ON one.pledge_date <= two.pledge_date
GROUP
BY two.pledge_date
simple, yes? 
i'm guessing you're on sql server, so you could also use WITH syntax instead of the view
Bookmarks