日期:2014-05-16 浏览次数:20572 次
create table tb(id int,date datetime,[count] int,[type] int)
insert into tb select 1,'2014-1-1',5,1
insert into tb select 2,'2014-1-2',4,2
insert into tb select 3,'2014-1-2',3,1
insert into tb select 4,'2014-1-3',7,2
insert into tb select 5,'2014-1-3',6,1
go
select *,(select sum([count]) from tb where id<=a.id and [type]=a.[type])as s from tb a
/*
id date count type s
----------- ----------------------- -----------&