I have product data in my table which looks similar to this
product_id | user_id | sales_start | sales_end | quantity |
---|---|---|---|---|
1 | 12 | 2022-01-01 | 2022-02-01 | 15 |
2 | 234 | 2022-11-01 | 2022-12-31 | 123 |
I want to transform the table into a daily snapshot so that it would look something like this:
product_id | user_id | quantity | date |
---|---|---|---|
1 | 12 | 15 | 2022-01-01 |
1 | 12 | 15 | 2022-01-02 |
1 | 12 | 15 | 2022-01-03 |
… | … | … | … |
2 | 234 | 123 | 2022-12-31 |
I know how to do a similar thing in Pandas, but I need to do it within AWS Athena.
I thought of getting the date interval and unnest it, but I am struggling with mapping them properly.
Any ideas on how to transform data?
2
Answers
You can use
sequnece
to generate dates range and thenunnest
it:Output:
This will help you
sequence