with recursive tbl as (
SELECT * FROM (values
(1,0),(2,0),(3,0),(4,3),
(5,0),(6,0),(7,4),
(8,0),(9,0),(10,7))
AS t(a,b)
)
,rez as (SELECT * FROM tbl where a=10
UNION
SELECT tbl.a,case when tbl.b=0 then rez.b else tbl.b end FROM tbl,rez where tbl.a=rez.a-1
)
SELECT * FROM rez order by a