I have the following data, as an example:
+------+-------------+
| price | date |
+-------+------------+
| 7 | 2023-01-04 |
| 9 | 2023-02-14 |
| 1 | 2023-04-12 |
| 3 | 2023-07-23 |
+-------+------------+
I need to repeat the price day by day, from the start date, until the next time it changes, or the current date. Example:
+------+-------------+
| price | date |
+-------+------------+
| 7 | 2023-01-04 |
| 7 | 2023-01-05 |
| 7 | 2023-01-06 |
| 7 | 2023-01-07 |
| 7 | 2023-01-08 |
| 7 | 2023-01-09 |
| 7 | 2023-01-10 |
| 7 | 2023-01-11 |
[...]
| 7 | 2023-02-13 |
| 9 | 2023-02-14 |
| 9 | 2023-02-15 |
[...]
| 3 | 2023-08-25 |
+-------+------------+
Why?
I'm using Metabase to create a trend graphic about the price of an item, and it needs to have the data consistently day-by-day, or week-by-week, etc.
What I have so far
On another question of mine, I was helped about creating the same value
month-by-month on a range of dates with the following code:
with recursive dates(name, date) as (
select name, startdate from mytable where name = 1
union all
select dates.name, dates.date + interval 1 month from dates join mytable using (name)
where dates.date < mytable.enddate
)
select * from dates;
Which in that case, would return:
+------+------------+
| name | date |
+------+------------+
| 1 | 2023-04-01 |
| 1 | 2023-05-01 |
| 1 | 2023-06-01 |
| 1 | 2023-07-01 |
+------+------------+
But now, it's kinda the same issue, but this time it repeats itself, until it changes on the following row.