create table tb(projID varchar(20),planmonth varchar(10),monthjzl int) insert into tb select 'aa','2008-02',100 insert into tb select 'aa','2008-03',200 insert into tb select 'bb','2008-03',100select projid,planmonth, monthjzl=(select sum(monthjzl) from tb where projID=t.projID and cast(planmonth+'-01' as datetime)<=cast(t.planmonth+'-01' as datetime)) from tb t projid planmonth monthjzl aa 2008-02 100 aa 2008-03 300 bb 2008-03 100 给你加了'-01',免得直接比较误差
insert into tb select 'aa','2008-02',100
insert into tb select 'aa','2008-03',200
insert into tb select 'bb','2008-03',100select projid,planmonth,
monthjzl=(select sum(monthjzl) from tb where projID=t.projID and cast(planmonth+'-01' as datetime)<=cast(t.planmonth+'-01' as datetime))
from tb t
projid planmonth monthjzl
aa 2008-02 100
aa 2008-03 300
bb 2008-03 100
给你加了'-01',免得直接比较误差