First page Back Continue Last page Image

A Window with a Frame using RANGE

SELECT vendor_id, invoice_date, invoice_total,

SUM(invoice_total) OVER(PARTITION BY vendor_id

ORDER BY invoice_date

RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW)

AS vendor_total

FROM invoices

WHERE invoice_date

BETWEEN '2018-04-01' AND '2018-04-30'

The Target data here is vendor_id by invoice_date but here we can see duplicates 2 invoices by the same vendor on the same day are treated as one object