select date,sum(qty) as daysum,sum=(select sum(qty) from tablename where [date]<=a.[date]) from tablename group by [date]
解决方案 »
- 如何清除数据库中表中的记录,并恢复标识列的初始值.
- 数据类型varchar转换为Numeric时出错,请问错在那里
- (急!)将SQL SERVER2000表中的数据导出到EXCEL中,使用存储过程实现,如何包含字段名?
- 怎样输出一个'符号???
- 无法把table数据导出到txt,
- 帮忙,SQL语句求解!!
- 石灰级的老鸟?请教[TCP/IP Sockets]、[DBNETLIB]的错误是怎么回事,如何解决??
- 70-228考试中大概有几题是关于复制的.
- 一个关于程贮过程刷新的问题!!
- 我希望大家能给我关于两个虚表用法的帮助!
- 急!如何连接触发器中的inserted和deleted表?
- 数据类型问题:一个数据库字段设定为FLOAT类型,输入数据为384.80,但用查询分析器查询的结果却变成了384.80000000000001,这是为什么?
select [date],daysum,[sum]=(select sum(qty) from tablename where [date]<=a.[date]) from (select [date],sum(qty) as daysum from tablename group by [date]) a
declare @table table(id int identity(1,1) ,date varchar(10),qty int)
insert into @table
select '20040101', 10
union all
select
'20040101', 20
union all
select
'20040102' ,10
union all
select
'20040103' ,20
union all
select
'20040104' ,30
union all
select
'20040105' ,10
union all
select
'20040105' ,10
union all
select
'20040106' ,50
union all
select
'20040106' ,10
union all
select
'20040106' ,10
select date,sum(qty),(select sum(qty) from @table where date<=O.date)
from @table O
group by date结果
20040101 30 30
20040102 10 40
20040103 20 60
20040104 30 90
20040105 20 110
20040106 70 180
Where date <= a.[date])) From 表 Order by date Group by date
Where date <= a.[date])) From 表 as a Order by date Group by date