日期:2014-05-18 浏览次数:20573 次
--> 测试数据:[表a]
if object_id('[表a]') is not null drop table [表a]
create table [表a]([名称] varchar(6),[数量1] int)
insert [表a]
select '篮球',2 union all
select '足球',3 union all
select '羽毛球',1
--> 测试数据:[表b]
if object_id('[表b]') is not null drop table [表b]
create table [表b]([名称] varchar(6),[数量2] int)
insert [表b]
select '篮球',4 union all
select '足球',4 union all
select '乒乓球',2
select isnull(a.名称,b.名称) as 名称,
isnull(a.数量1,0) 数量1,isnull(b.数量2,0) as 数量2 from [表a] a
full join [表b] b on a.名称=b.名称
/*
名称 数量1 数量2
篮球 2 4
足球 3 4
羽毛球 1 0
乒乓球 0 2
*/