日期:2014-05-16 浏览次数:20528 次
create table Intable(
Code varchar(20),
amount decimal(10,3)
)
insert into Intable values ('1',10)
insert into Intable values ('2',30)
create table Outtable(
Code varchar(20),
amount decimal(10,3)
)
insert into Outtable values ('1',2)
insert into Outtable values ('1',5)
insert into Outtable values ('2',10)
select * from Intable
select * from Outtable
select distinct A.Code,
A.amount-SUM(B.amount)over (partition by B.code) from Intable A inner join Outtable B on A.Code=B.Code