select A.MC MC1, c.MC MC2
from B left join A
on B.BM1 = A.BM
left join A c 
on B.BM2 = c.BM

解决方案 »

  1.   

    create table #T1(BM int, MC varchar(20))
    create table #T2(BM1 int, BM2 int)
    Create table #T3 (MC1 varchar(20), MC2 varchar(20), BM1 int, BM2 int)
    Insert #t1(BM, MC) values (1, '北京')
    Insert #t1 (BM, MC) values (2, '天津')
    Insert #t1 (BM, MC) values (3, '上海')  
    Insert #t1 (BM, MC) values (4, '重庆')
    Insert #T2 (BM1, BM2) values (1, 2)
    Insert #T2 (BM1, BM2) values (1, 4)
    Insert #T2 (BM1, BM2) values (2, 3)  
    Insert #T3 (BM1, BM2) select BM1, BM2 From #t2
    Update #T3 set MC1 = mc from #t1 where BM = BM1
    Update #T3 set MC2 = MC from #t1 where BM = BM2select * from #t3