Add rows based on Start and End Date

Options

I have the following table within my output

Cust_No Start_Date End_Date Comp_Val Monthly_Val
123 2023-01-01 2023-06-30 1100 55.95
123 2023-07-01 2024-02-05 1100 22.90

As you can see, the months between start_date and end_date for this example, is 13+ months.

What I would like to see is a row for each Year_Month between Start_Date and End_Date with a new variable added (Year_Month)

Example

Cust_No Start_Date End_Date Comp_Val Monthly_Val Year_Month
123 2023-01-01 2023-01-30 1100 55.95 2023-01
123 2023-02-01 2023-02-28 1100 55.95 2023-02
123 2023-03-01 2023-03-31 1100 55.95 2023-03
123 2023-04-01 2023-04-30 1100 55.95 2023-04
123 2023-05-01 2023-05-31 1100 55.95 2023-05
123 2023-06-01 2023-06-30 1100 55.95 2023-06
123 2023-07-01 2023-07-31 1100 22.90 2023-07
123 2023-08-01 2023-08-31 1100 22.90 2023-08
123 2023-09-01 2023-09-30 1100 22.90 2023-09
123 2023-10-01 2023-10-31 1100 22.90 2023-10
123 2023-11-01 2023-11-30 1100 22.90 2023-11
123 2023-12-01 2023-12-31 1100 22.90 2023-22
123 2024-01-01 2024-01-31 1100 22.90 2024-01
123 2024-02-01 2024-02-05 1100 22.90 2024-02

I would like to do this in MySQL or ETL data flow if possible. Thanks in advance!

Best Answer

Answers