Skip to main content
tag, minor edits
Source Link
Erwin Brandstetter
  • 182.1k
  • 28
  • 457
  • 620

I have a view which calculates rolling sum taking in value form previous row based on PARTITION BY clause, and I need to indicate one field Im using in PARTITION BYPARTITION BY clause can have nulls in them.

sum(s."QuantityChange") OVER (PARTITION BY s."LocationId", s."PartId", s."SupplierFacilityId" ORDER BY s."DueDate" ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS "RunningSum"

sometimesSometimes SupplierFacilityId is null and that's fine, it should still be included in the sum()sum() calculation.

Is this possible with Postgres?

I have a view which calculates rolling sum taking in value form previous row based on PARTITION BY clause, and I need to indicate one field Im using in PARTITION BY clause can have nulls in them.

sum(s."QuantityChange") OVER (PARTITION BY s."LocationId", s."PartId", s."SupplierFacilityId" ORDER BY s."DueDate" ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS "RunningSum"

sometimes SupplierFacilityId is null and that's fine, it should still be included in the sum() calculation.

Is this possible with Postgres?

I have a view which calculates rolling sum taking in value form previous row based on PARTITION BY clause, and I need to indicate one field in PARTITION BY clause can have nulls in them.

sum(s."QuantityChange") OVER (PARTITION BY s."LocationId", s."PartId", s."SupplierFacilityId" ORDER BY s."DueDate" ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS "RunningSum"

Sometimes SupplierFacilityId is null and that's fine, it should still be included in the sum() calculation.

Is this possible with Postgres?

Source Link
vmachacek
  • 103
  • 1
  • 4

Postgres SUM over PARTITION BY "tolerate" null values

I have a view which calculates rolling sum taking in value form previous row based on PARTITION BY clause, and I need to indicate one field Im using in PARTITION BY clause can have nulls in them.

sum(s."QuantityChange") OVER (PARTITION BY s."LocationId", s."PartId", s."SupplierFacilityId" ORDER BY s."DueDate" ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS "RunningSum"

sometimes SupplierFacilityId is null and that's fine, it should still be included in the sum() calculation.

Is this possible with Postgres?