不知道是不是这个意思!?create table A
(
id int,
Quantity int
)create table B
(
id int,
Foreignid int,
Quantity int
)insert A select 1,10insert B select 1,1,2
insert B select 2,1,3
insert B select 3,1,1select Quantity from B where Foreignid in (select A.id from A,(select Foreignid,sum(Quantity) as Tq from B group by Foreignid) T where A.id=T.Foreignid and A.Quantity>=T.Tq )
union all
select A.Quantity-T.Tq as Quantity from A,(select Foreignid,sum(Quantity) as Tq from B group by Foreignid) T where A.id=T.Foreignid and A.Quantity>=T.Tq
(
id int,
Quantity int
)create table B
(
id int,
Foreignid int,
Quantity int
)insert A select 1,10insert B select 1,1,2
insert B select 2,1,3
insert B select 3,1,1select Quantity from B where Foreignid in (select A.id from A,(select Foreignid,sum(Quantity) as Tq from B group by Foreignid) T where A.id=T.Foreignid and A.Quantity>=T.Tq )
union all
select A.Quantity-T.Tq as Quantity from A,(select Foreignid,sum(Quantity) as Tq from B group by Foreignid) T where A.id=T.Foreignid and A.Quantity>=T.Tq
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货