I have a table that gives me data every month and I need that range of time. I noticed that sometimes I don't have data for 3/4 month but I need to duplicate the last row available with the missing timestamp.
Example:
product_id | total_revenue | yearmonth |
---|---|---|
1 | 50 | 202201 |
2 | 17 | 202201 |
3 | 30 | 202201 |
1 | 67 | 202202 |
2 | 31 | 202202 |
1 | 67 | 202203 |
2 | 31 | 202203 |
3 | 33 | 202203 |
But I need an output like:
product_id | total_revenue | yearmonth |
---|---|---|
1 | 50 | 202201 |
2 | 17 | 202201 |
3 | 30 | 202201 |
1 | 67 | 202202 |
2 | 31 | 202202 |
3 | 30 | 202202 |
1 | 67 | 202203 |
2 | 31 | 202203 |
3 | 33 | 202203 |
I have a select statement like:
select
product_id, total_revenue, yearmonth
from
revenue
I found a similar question, (Postgresql compare consecutive rows and insert identical row if there are no values) but in Impala I have not the lateral join, does anybody know how can I do?