日期:2014-05-16 浏览次数:20710 次
create table test1(ID nvarchar(10),数量 int)
insert test1
select '00001',50 union all
select '00001',50 union all
select '00001',40 union all
select '00002',50 union all
select '00002',60 union all
select '00002',50 union all
select '00003',100 union all
select '00003',100
create table test2(ID nvarchar(10),数量 int)
insert test2
select '00001',200 union all
select '00002',200 union all
select '00003',500
create table test3(ID nvarchar(10),数量 int)
insert test3
select '00001',60 union all
select '00002',40 union all
select '00003',300
select *
from (
select ID,数量=SUM(数量)
from test1
group by ID
) a
inner join test2 b
on a.ID=b.ID
inner join test3 c
on a.ID=c.ID
where a.数量<>(b.数量-c.数量)