一个SQL问题,好象有点难...在线给分... update tableaset t4 = t4 - (select sum(t3) from tablea where a.t2 = t2 and t1<= a.tid )from tablea a 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 create table t(t1 int,t2 char(2),t3 int,t4 int)insert t select 1,'A1',20,100 union allselect 2,'A1',20,100 union allselect 3,'A2',10,50 union allselect 4,'A2',20,50 union allselect 5,'A1',10,100 union allselect 6,'A2',5,50goselect * from tupdate tset t4 = t4 - (select sum(t3) from t where a.t2 = t2 and t1<= a.t1 )from t aselect * from tdrop table t/*t1 t2 t3 t4 ----------- ---- ----------- ----------- 1 A1 20 1002 A1 20 1003 A2 10 504 A2 20 505 A1 10 1006 A2 5 50(所影响的行数为 6 行)(所影响的行数为 6 行)t1 t2 t3 t4 ----------- ---- ----------- ----------- 1 A1 20 802 A1 20 603 A2 10 404 A2 20 205 A1 10 506 A2 5 15(所影响的行数为 6 行)*/ update table set t4=t4 - (select sum(t3) from table where t2=a.t2 and t1<=a.t1)from table a declare @t table(t1 int,t2 varchar(10),t3 int,t4 int)insert into @t select 1,'A1',20,100insert into @t select 2,'A1',20,100insert into @t select 3,'A2',10,50insert into @t select 4,'A2',20,50insert into @t select 5,'A1',10,100insert into @t select 6,'A2',5 ,50update aset t4=a.t4-(select sum(t3) from @t where t2=a.t2 and t1<=a.t1) from @t aselect * from @t/*t1 t2 t3 t4 ----------- ---------- ----------- ----------- 1 A1 20 802 A1 20 603 A2 10 404 A2 20 205 A1 10 506 A2 5 15*/ replace的使用,在线等,马上给分啊 请首席专家 邹建 等朋友 帮我分析分析 (诚恳请教)得出问题立即结贴 数何只读取第10行到第20行的数据? SQL数据库如何保存条形码 高手进来!!!快!!!! 代码问题!!给分!! SQL SERVER中主键是自动增加的吗? 如何把一个ACCESS表中删除的记录自动添加到另一个表中? 在powerbuilder区没有很好的解答 就发在这里吧 关于Access数据库性能的一个问题 有关查询的问题,请大家帮忙看看 关于SQLSERVER数据量的问题。。
insert t
select 1,'A1',20,100 union all
select 2,'A1',20,100 union all
select 3,'A2',10,50 union all
select 4,'A2',20,50 union all
select 5,'A1',10,100 union all
select 6,'A2',5,50
go
select * from t
update t
set t4 = t4 - (select sum(t3)
from t
where a.t2 = t2 and t1<= a.t1 )
from t a
select * from tdrop table t/*
t1 t2 t3 t4
----------- ---- ----------- -----------
1 A1 20 100
2 A1 20 100
3 A2 10 50
4 A2 20 50
5 A1 10 100
6 A2 5 50(所影响的行数为 6 行)
(所影响的行数为 6 行)t1 t2 t3 t4
----------- ---- ----------- -----------
1 A1 20 80
2 A1 20 60
3 A2 10 40
4 A2 20 20
5 A1 10 50
6 A2 5 15(所影响的行数为 6 行)
*/
from table a
insert into @t select 1,'A1',20,100
insert into @t select 2,'A1',20,100
insert into @t select 3,'A2',10,50
insert into @t select 4,'A2',20,50
insert into @t select 5,'A1',10,100
insert into @t select 6,'A2',5 ,50update a
set
t4=a.t4-(select sum(t3) from @t where t2=a.t2 and t1<=a.t1)
from
@t aselect * from @t/*
t1 t2 t3 t4
----------- ---------- ----------- -----------
1 A1 20 80
2 A1 20 60
3 A2 10 40
4 A2 20 20
5 A1 10 50
6 A2 5 15
*/