原表中数据:
year salary
—————————————–
2000 1000
2001 2000
2002 3000
2003 4000
结果表中数据:
year salary
——————————————
2000 1000
2001 3000
2002 6000
2003 10000
写出SQL语句如下:
create table test([year] int ,salary int)
insert test(year,salary) values(2000,1000)
insert test(year,salary) values(2001,2000)
insert test(year,salary) values(2002,3000)
insert test(year,salary) values(2003,4000)
select t1.year, (select sum(salary) from test as t2 where t2.year