用递归
CTE:
with recursive cte as ( select name, course, sdate, edate from tablename union all select name, course, sdate + interval 1 month, edate from cte where last_day(sdate) < edate)select name, course, date_format(sdate, '%Y-%m') enrollMonthfrom cte
参见演示。
结果:
> name | course | enrollMonth> :------ | :----------- | :----------> Tanzeel | SQL Bootcamp | 2019-05 > Tanzeel | SQL Bootcamp | 2019-06 > Tanzeel | SQL Bootcamp | 2019-07 > Tanzeel | SQL Bootcamp | 2019-08 > Tanzeel | SQL Bootcamp | 2019-09 > Tanzeel | SQL Bootcamp | 2019-10 > Tanzeel | SQL Bootcamp | 2019-11



