日期:2014-05-17 浏览次数:20484 次
create table #t1
(
a1 varchar(10),
a2 varchar(10),
a3 varchar(10),
a4 varchar(10),
a5 varchar(10)
)
create table #t2
(
b1 varchar(10),
b2 varchar(10),
b3 varchar(10),
b4 varchar(10),
b5 varchar(10)
)
insert #t1
select '1x', '2x', '3x', '4x', '5x' union all
select '1a', '2a', '3a', '4a', '5a'
insert #t2
select '1x', '2x', 'a', 'a', '欧莱雅' union all
select '1x', '2x', 'c', 'c', '潘婷' union all
select '1a', '2a', 'a', 'b', '欧莱雅' union all
select '1a', '2a', 'a', 'b', '潘婷'
select t1.a1,t1.a2,max(t2.b3)as b3 ,max(t2.b4) as b4,max(t2.b5) as b5
from #t1 t1
left join #t2 t2 on t1.a1=t2.b1 and t1.a2=t2.b2