select ID,FORID,FSUM,FDate,(FSUM+iif(isnull((select sum(FSUM) from 表 where ID <t.ID)),0,(select sum(FSUM) from 表 where ID <t.ID))) as ffsum from 表 t SQL code: select a.ID,a.FORID,a.FSUM,a.FDate,sum(b.FSUM) as ffsum from 表 a ,表 b where a.FORID=b.FORID and a.ID>=b.ID group by a.ID,a.FORID,a.FSUM,a.FDate
精简一下: select ID,FORID,FSUM,FDate,(select sum(FSUM) from 表 where ID <=t.ID) as ffsu