日期:2014-05-18 浏览次数:20785 次
create table table_1
(
f_key int
, f_IsSysSN int
, f_Qty int
)
go
insert into table_1
select 1001,0,0 union all
select 1001,3,0 union all
select 1001,5,0 union all
select 1002,2,0 union all
select 1002,2,0
go
update table_1 set f_qty=(select sum(f_issyssn) from table_1 where f_key=1001 group by f_key )
where f_key=1001
update table_1 set f_qty=(select sum(f_issyssn) from table_1 where f_key=1002 group by f_key )
where f_key=1002
select * from table_1
f_key f_IsSysSN f_Qty
----------- ----------- -----------
1001 0 8
1001 3 8
1001 5 8
1002 2 4
1002 2 4
(5 行受影响)