易截截图软件、单文件、免安装、纯绿色、仅160KB

求SQL语句



ID,FORID,FSUM,FDate
1  1    20  2009-01-01
2  1    30  2009-02-01
3  1    40  2009-03-01
4  2    10  2009-01-01

查询结果


ID,FORID,FSUM,FDate          ffsum
1  1    20  2009-01-01    20
2  1    30  2009-02-01    50
3  1    40  2009-03-01    90
4  2    10  2009-01-01    10

多生成一列FFsum,相同ForID,累加日期前的fsum值


select ID,FORID,FSUM,FDate,(FSUM+iif(isnull((select sum(FSUM) from 表 where ID <t.ID)),0,(select sum(FSUM) from 表 where ID <t.ID))) as ffsum from 表 t

SQL code:
select a.ID,a.FORID,a.FSUM,a.FDate,sum(b.FSUM) as ffsum
from 表 a ,表 b
where a.FORID=b.FORID and a.ID>=b.ID
group by a.ID,a.FORID,a.FSUM,a.FDate


引用
select ID,FORID,FSUM,FDate,(FSUM+iif(isnull((select sum(FSUM) from 表 where ID <t.ID)),0,(select sum(FSUM) from 表 where ID <t.ID))) as ffsum from 表 t


精简一下:
select ID,FORID,FSUM,FDate,(select sum(FSUM) from 表 where ID <=t.ID) as ffsu


相关问答:

jsp链接sql2000的疑问?



type Exception report


message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jas ......

sql性能求助 - MS-SQL Server / 疑难问题

场景如下:
客户把备份好的数据库,发给我,我在本机还原后,运行写好的存储过程,比较快,并且在实施那边运行同样比较快。但是当实施在客户那边运行的时候速度就非常的慢,时间超出了程序的时间限制。远程在客户那 ......

请教sql语句。 - Oracle / 开发

我有一个表,结构是这样。
  转出 单位 转入单位 笔数 金额
date(主) outid(主) inid(主) num amt
2009 1 2 1 500 为 1 单位 在2009� ......

pl/sql - Oracle / 开发

小弟,最近要转行去做oracle开发了,由于大学毕业时,走了个弯路,现在很小心,问下,做PL/SQL有没有前途???
当然我说的这个前途是指 以后要跳槽,市场对这样的人才的需求量大不大??

3q 那看来还只能先接� ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号