这可能会对您有所帮助。
select a.id, a.length, coalesce(a.length - (select b.length from foo b where b.id = a.id + 1), a.length) as difffrom foo a

这可能会对您有所帮助。
select a.id, a.length, coalesce(a.length - (select b.length from foo b where b.id = a.id + 1), a.length) as difffrom foo a