select YMDHM,DTRN,D=(
select sum(DTRN) from a
where YMDHM<=aa.YMDHM and datediff(day,YMDHM,a.YMDHM)=0)
from a aa
select sum(DTRN) from a
where YMDHM<=aa.YMDHM and datediff(day,YMDHM,a.YMDHM)=0)
from a aa
解决方案 »
- 用SQL 2005 存储过程实现数据展现
- 请高手帮我写条SQL语句
- 如何把oracle的存储过程转换为MSSQL的存储过程,有没有相关的工具
- 怎样实现这样的SQL,搞不定,求救~,谢谢
- 行转列问题
- 在SQL数据库中联机数据库时遇到如下错误,请问如何解决?执行 Transact-SQL 语句或批处理时发生了异常
- 小弟初学sql server,请问写存储过程的脚本语言是如何学习的,好像跟上学时学的sql不完全一样的
- SQL复制问题?
- 请教:没有为第 2 列(属于 't')指定列。
- 存储过程是可否select进行嵌套呢?
- 各位大哥!!!救命...............
- 我想用 PROFILER 来 TRACE 一个特定软件对我服务器的所有动作,遇到一些问题请帮忙
select sum(DTRN) from a
where YMDHM<=aa.YMDHM and datediff(day,YMDHM,aa.YMDHM)=0)
from a aa
create table a(YMDHM Datetime,DTRN Numeric(5,1))
insert a select '2004-4-8 23:00:00', 1
union all select '2004-4-9 00:00:00', 0
union all select '2004-4-9 01:00:00',0.5
union all select '2004-4-9 02:00:00', 1
union all select '2004-4-9 03:00:00',0.5
union all select '2004-4-9 04:00:00',1.5
go--查询
select YMDHM,DTRN,D=(
select sum(DTRN) from a
where YMDHM<=aa.YMDHM and datediff(day,YMDHM,aa.YMDHM)=0)
from a aa
go--删除测试
drop table a/*--测试结果YMDHM DTRN D
------------------------------------------------------ ------- --------
2004-04-08 23:00:00.000 1.0 1.0
2004-04-09 00:00:00.000 .0 .0
2004-04-09 01:00:00.000 .5 .5
2004-04-09 02:00:00.000 1.0 1.5
2004-04-09 03:00:00.000 .5 2.0
2004-04-09 04:00:00.000 1.5 3.5(所影响的行数为 6 行)--*/