-- 若不考虑拆单,id为主键id,`week` 字段作为每单的需求量;按最终的 CEI_num字段,1为第一天,2为第二天,以此类推,匹配所需要日期就行了
SELECT
t1.id -- 想象为单号
,t1.`week` AS NUM1 -- 每期需求量
,sum(t2.`week`) AS TOTAL_NUM -- 累计量
,MOD(sum(t2.`week`),40) AS mod_num -- 按每日40 余数
,CEILING(sum(t2.`week`)/40) AS CEI_num -- 取整数
FROM test1.work_day1 t1 JOIN test1.work_day1 t2
ON t1.id>=t2.id
GROUP BY t1.id