Hvis du beslutter dig for at opgradere til MySQL 8.0, er her en rekursiv CTE, der vil generere en liste over alle dage mellem planning_start_date
og planning_end_date
sammen med den nødvendige daglige mængde:
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`