求一sql语句(如何求得每年的合计),谢谢 没有看懂 ,年的合计小于累计合计, 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 用游标,把当前的累计合计减去去年的累计合计就可以得本年合计 --e.g.create table #test(年份 int,累计合计 int)insert #test select 2001,10000union select 2002,18000union select 2003,23000select * from #testselect 年份,累计合计,累计合计-isNull((select 累计合计 from #test where 年份=a.年份-1),0) 本年合计 from #test adrop table #test 年份 累计合计 ----------- ----------- 2001 100002002 180002003 23000(所影响的行数为 3 行)年份 累计合计 本年合计 ----------- ----------- ----------- 2001 10000 100002002 18000 80002003 23000 5000(所影响的行数为 3 行) SQL 工具书 很小的问题,请各位大哥帮帮忙? MICROSOFT.JET.OLEDB.4.0非常慢,最后超时 请问这个表的结构和主键外键怎么设置? ms sql2000检索中文标点 SQL.LOG为什么越来越大,SQLServer越来越慢? 索引和关键字有什么区别?还有依赖于通俗点怎么讲? 求教 特殊存储过程的写法? 关于SQL SERVER的用户和口令 一个连接服务器插入数据的问题? 如何比较这两个字符串? 英文环境中使用简体中文程序的汉字显示问题
create table #test(年份 int,累计合计 int)
insert #test
select 2001,10000
union select 2002,18000
union select 2003,23000select * from #test
select 年份,累计合计,累计合计-isNull((select 累计合计 from #test where 年份=a.年份-1),0) 本年合计 from #test a
drop table #test
----------- -----------
2001 10000
2002 18000
2003 23000(所影响的行数为 3 行)年份 累计合计 本年合计
----------- ----------- -----------
2001 10000 10000
2002 18000 8000
2003 23000 5000(所影响的行数为 3 行)