SELECT 时间段id, LAST_VALUE(CASE WHEN 工单数量 > 0 THEN 工单数量 END IGNORE NULLS) OVER (ORDER BY 时间段id ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS 工单数量 FROM 工单表;
SELECT A.ID,(CASE WHEN A.数量=0 THEN (SELECT B.数量 FROM TABLENAME B WHERE B.ID<A.ID AND B.数量>0 order by b.id DESC LIMIT 1) ELSE A.数量 END) [数量] FROM TABLENAME A