日期:2014-05-18  浏览次数:20671 次

问个设计方面的问题,进出存系统要在本月报表查到上月的结余怎么设计数据库啊??
如题~

------解决方案--------------------
数据库记录:
ID NumNo 要求出的结果
1 20 20
2 -8 12
3 -3 9
4 11 20
5 -4 16

declare @t table(ID int,NumNo int)
insert into @t select 1,20
insert into @t select 2,-8
insert into @t select 3,-3
insert into @t select 4,11
insert into @t select 5,-4

select ID,NumNo,(select sum(NumNo) from @t where ID <=a.ID) as 要求出的结果 from @t a


ID NumNo 要求出的结果
----------- ----------- -----------
1 20 20
2 -8 12
3 -3 9
4 11 20
5 -4 16

(所影响的行数为 5 行)