---测试脚本
-------------------------------------
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[moneyTable]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[moneyTable]
GO
CREATE TABLE [dbo].[moneyTable] (
[Mid] [bigint] IDENTITY (1, 1) NOT NULL ,
[a] [bigint] NULL ,
[b] [bigint] NULL
) ON [PRIMARY]
GO
insert into moneyTable(a,b) values(90,70)
insert into moneyTable(a,b) values(100,90)
insert into moneyTable(a,b) values(54,63)
select a,b,(select sum(a)-sum(b) from moneyTable as money1 where money2.mid>=money1.mid) as 余额 from moneyTable as money2
drop table moneyTable
-------------------------------------------
---测试脚本
-------------------------------------
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[money]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[money]
GO
CREATE TABLE [dbo].[money] (
[a] [bigint] NULL ,
[b] [bigint] NULL
) ON [PRIMARY]
GO
insert into money(a,b) values(90,70)
insert into money(a,b) values(100,90)
select a,b,a-b as c from money
drop table money
-------------------------------------------