Home > Net >  SQL View use date between 2 dates
SQL View use date between 2 dates

Time:08-27

I'm doing som data analysis and then I have a clear challenge, that i need some help for:

I've have table containing these:

VIN(Uniq Identifier for the car) - startDate - endDate - amountSpend
XYSBBNXZXDXAQ - 1-8-2022 - 30-8-2022 - 100.000,00
XCHEFFACSKNKN - 15-8-2022 - 30-8-2022 - 150.000,00

And then I would like to create a view like this:

Date - amountSpend
1-8-2022 - 100.000,00
2-8-2022 - 100.000,00
3-8-2022 - 100.000,00
.....
15-8-2022 - 250.000,00
16-8-2022 - 250.000,00

I'm running on PostgreSQL

Anyone there can point me into a direction of how to solve this in pos

CodePudding user response:

You can use lateral along with generate_series:

select v.VIN, t.d, v.amountSpend from vehicles v,
    lateral generate_series(startDate, enddate, '1 day') t(d);

Here is DBFiddle demo

  • Related