日期:2014-05-17 浏览次数:20616 次
create table table1(Col1 varchar(10), Col2 int)
insert into table1
select '0001', 3 union all
select '0002', 4 union all
select '0002', 5
create table table2(Col1 varchar(10), Col3 int)
insert into table2
select '0002', 6
go
select t1.Col1,t1.Col2,
case when row_number() over(PARTITION by t1.col1
order by @@servername)=1
then t2.Col3
else null
end as col3
from table1 t1
left join table2 t2
on t1.Col1 = t2.Col1
/*
Col1 Col2 col3
0001 3 NULL
0002 4 6
0002 5 NULL
*/