I have this data in mysql 5.7
drop table if exists t_test;
create table t_test (
dates date,
num int
);
insert into t_test values('2022-02-01', 10), ('2022-02-10', 20);
How to get this data with sql? date_add('2022-02-01', interval 30 day)
= 2023-03-03
dates | num |
---|---|
2022-02-01 | 10 |
2022-02-02 | 10 |
… | … |
2022-02-09 | 10 |
2022-02-10 | 20 |
2022-02-11 | 20 |
… | … |
2022-03-03 | 20 |
2
Answers
This can be done using a recursive CTE :
Demo here
It’s not pretty but you could use something like the following:
If you want more than 39 days then you can increase the size of seq2.
Here’s a db<>fiddle