有表共两个字段:[date] [count]
2003-01-01 1
2003-01-03 2
2003-01-04 3
2003-01-06 5
..................
---------------------------------
怎样得到结果: [date] [total]---->为大于该日期的所有[count]的和
2003-01-01 1
2003-01-03 3
2003-01-04 6
2003-01-06 11
..................
select date,sum(count) as total from t1 group by date
select date, sum(count) as total from t1
where date < (select date from t1)
declare @count int
set @count=0
update tablename set @count=count=@count+count
select [date],sum(select count from t1 where [date]<t1.[date]) as total from t1
select a.[date],
(select sum(b.count) from 表 b where b.date<=a.date) as total
from 表 a
select [date],sum(select count from t1 where [date]<= a.[date]) as total
from t1 a
如果是查询,就用楼上的
select a.[date],
(select sum(b.count) from t1 b where b.date<=a.date) as total
from t1 a
update table1
set [count]=(select sum([count]) from table1 where [date] <= A.[date])
from table1 A
select a.[date],
(select sum(b.[count]) from 表 b where b.[date]<=a.[date]) as total
from 表 a