full join 的一个小应用
create table table1(pid int,product varchar(20),inputNum int)
go
insert into table1 select 1,'A',20
insert into table1 select 3,'C',10
insert into table1 select 5,'E',30
create table table2(pid int,product varchar(20),outputNum int)
go
insert into table2 select 1,'A',30
insert into table2 select 2,'B',8
insert into table2 select 4,'D',15
go
select isnull(t1.pid,t2.pid) as pid,isnull(t1.product,t2.product) as product,isnull(inputnum,0) as inputnum,isnull(outputnum,0) as outputnum
from table1 t1 full join table2 t2
on t1.pid=t2.pid
order by pid
go
drop table table1,table2
go
/*结果
pid product inputnum outputnum
----------- -------------------- ----------- -----------
1 A 20 30
2 B 0 8
3 C 10 0
4 D 0 15
5 E 30 0

浙公网安备 33010602011771号