来 看图“作文”的时间到了 囧
-------------
从有限的信息来模拟
with TEST as (
select 1 [rank],912 [投入],0 [报废]
union ALL
select 2 [rank],912 [投入],0 [报废]
union ALL
select 3 [rank],912 [投入],0 [报废]
union ALL
select 4 [rank],912 [投入],300 [报废]
union ALL
select 5 [rank],null [投入],null [报废]
union ALL
select 6 [rank],null [投入],null [报废]
union ALL
select 7 [rank],612 [投入],0 [报废]
union ALL
select 8 [rank],null [投入],0 [报废]
union ALL
select 9 [rank],null [投入],0 [报废]
union ALL
select 10 [rank],null [投入],0 [报废]
union ALL
select 11 [rank],null [投入],null [报废]
union ALL
select 12 [rank],612 [投入],0 [报废]
)
SELECT *,(case when 投入 is null then (select top 1 投入-报废 from TEST b where b.rank<a.rank and b.投入 is not null order by b.rank desc ) else 投入 end) [投入_] FROM TEST a