select *,(select sum(a0-a3) from a where cdb=x.cdb and (tyear<x.tyear or tyear=x.tyear and tmonth<=x.tmonth)) as a4
from a x
order by cdb,tyear,tmonth
from a x
order by cdb,tyear,tmonth
调试欢乐多
(
select sum(a0-a3)
from a
where cdb=x.cdb and tyear =x.tyear and tmonth<=x.tmonth --我改一下这里
) as a4
from a x
order by cdb,tyear,tmonth