I have the following view which calculates the percentage increase of the site resources used for each date per site id:

table with percentage increases

What I'm trying to accomplish, is to add an extra column which will show the sum total of all previous percentage increases on each row. So the final table should look like this:

table with total sums column

Column1 here is just to further clarify the exact idea I'm trying to accomplish here. Each row in the 'total percentage by date' column should display the sum total of the current row + all the previous rows' 'percentage increase for date' values.

All solutions I have found so far for this won't work in postgres. Any help would be greatly appreciated.

  • SUM(percentage) OVER (PARTITION BY site_id ORDER BY date) May 2, 2020 at 15:54

1 Answer 1


You can use cross apply

SELECT d.*, di.p
FROM Data d
SELECT SUM(di.Persent) AS p
FROM Data di
WHERE di.AccesDate <= d.AccesDate
AND di.SiteID = d.SiteID
) di ON TRUE ;
  • Thanks for the help but CROSS APPLY is not a postgresql statement. Thus I cannot use it unfortunately. May 2, 2020 at 15:11
  • I edit my answer. May 2, 2020 at 17:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.