eclare @a table (收入 int, 付出 int , 余额 int)insert into @a
select 15, 13 , 0
union all
select 12, 10,0
union
select 9, 10,0declare @i int
set @i = 0
update @a set @i = 收入 - 付出 + @i , 余额 = @i
select * from @a
select 15, 13 , 0
union all
select 12, 10,0
union
select 9, 10,0declare @i int
set @i = 0
update @a set @i = 收入 - 付出 + @i , 余额 = @i
select * from @a
解决方案 »
- 表中数据很少,可是MDF文件却无法收缩了。
- 事务的问题!
- 十万火急,数据库启动不了该怎么办??谢谢,在线等!!!
- 我用以前的一个数据库备份更新了现在的库,还能还原回来吗?拜托各位兄弟
- 怎样使数据库般到另一个服务中能使用
- 用标准的SQL语句,怎样输出如下结果:
- sql字段问题,急!!!!!!!!!!!!!!!!!!
- 相当急!本地服务器不能连接,高手请帮助
- 我把doc、jpeg、text等文件写入sql2000的image类型字段中,现在希望把它们从image中读出并生成一个文件,或者直接显示在网页上,用asp.net
- 求助:SQL语句 当表2 或 表3 或 表4 或 表5 或 表6任一一个表出现新增、修改、删除时,表1会自动更新
- 高分求助,在线等待一个trigger 触发过程的编辑
- 在asp中,对ms sql 操作,返回记录先按用户排序,用户相同按时间排序的sql语句怎写?
select 15, 13 , 0
union all
select 12, 10,0
union all
select 9, 10,0declare @i int
set @i = 0
update @a set @i = 收入 - 付出 + @i , 余额 = @i
select * from @a
-------------------------------------
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[money]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[money]
GOCREATE TABLE [dbo].[money] (
[a] [bigint] NULL ,
[b] [bigint] NULL
) ON [PRIMARY]
GOinsert into money(a,b) values(90,70)
insert into money(a,b) values(100,90)select a,b,a-b as c from moneydrop table money
-------------------------------------------
你这样的话,只能是余额了,而我要的是余额不是这样的,你看一下
create table fc_sum
(
收入 int,
付出 int,
idh int
)
insert into fc_sum(收入 , 付出) values (15,13,1)
insert into fc_sum(收入 , 付出) values (12,10,2)
insert into fc_sum(收入 , 付出) values (9,10,3)*/select t.收入 ,t.付出,(select sum(收入-付出) from fc_sum where idh<=t.idh) as 合计
from fc_sum t
-------------------------------------
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[moneyTable]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[moneyTable]
GOCREATE TABLE [dbo].[moneyTable] (
[Mid] [bigint] IDENTITY (1, 1) NOT NULL ,
[a] [bigint] NULL ,
[b] [bigint] NULL
) ON [PRIMARY]
GOinsert 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 money2drop table moneyTable
-------------------------------------------