Ако решите да надстроите до MySQL 8.0, ето рекурсивен CTE, който ще генерира списък с всички дни между planning_start_date
и planning_end_date
заедно с необходимото дневно количество:
WITH RECURSIVE cte AS (
SELECT planning_start_date AS date,
planning_end_date,
quantity / (DATEDIFF(planning_end_date, planning_start_date) + 1) AS daily_qty
FROM test
UNION ALL
SELECT date + INTERVAL 1 DAY, planning_end_date, daily_qty
FROM cte
WHERE date < planning_end_date
)
SELECT `date`, daily_qty
FROM cte
ORDER BY `date`