两个表简单的合并
create table #A(a varchar(2),b varchar(2))sql 合并
create table #B(a varchar(2),c varchar(2))
insert into #A(a,b)
select 'A1','B1' UNION ALL
select 'A1','B2' UNION ALL
select 'A1','B3' UNION ALL
select 'A2','B1' UNION ALL
select 'A2',''
insert into #B(a,c)
select 'A1','C1' UNION ALL
select 'A1','C2' UNION ALL
select 'A2','C1' UNION ALL
select 'A2','C2'
得到如下
A1,B1,C1
A1,B2,C2
A1,B3,
A2,B1,C1
A2, ,C2
SELECT a.a,a.b,b.c FROM #A a
LEFT JOIN #B b
ON a.a=b.a AND RIGHT(a.b,1)=RIGHT(b.c,1)
用left join ,但是好像你条件不够,还是我不会写