create table testDB
(
id int identity(1,1) primary key,
name varchar(20) not null,
sales dec(18,2)
)

insert into testDB values('张三',10)
insert into testDB values('李四',20)
insert into testDB values('王五',30)
insert into testDB values('赵立权',40)
insert into testDB values('张华',50)
insert into testDB values('周杰',60)

select * from testDB
select id,name,sales,(select sum(sales) from testDB where id<=a.id) as 'total' from testDB a

posted on 2013-02-22 22:00  Haydy  阅读(270)  评论(0编辑  收藏  举报