I have a massive table with records that all have a date and a price:
id | date | price | etc...
And then I have a list of random date ranges, never with the same length:
ARRAY [
daterange('2020-11-02','2020-11-05'),
daterange('2020-11-15','2020-11-20')
]
How would I most efficiently go about summing and grouping the records by their existence in one of the ranges, like so:
range | sum
------------------------------------------
[2020-11-02,2020-11-05) | 125.55
[2020-11-15,2020-11-20) | 566.12