列1 列2 列3 列4 列5 列6
1 AAA 2 2 BBB BBB
2 BBB 2 2 BBB BBB
3 CCC 2 2 BBB BBB
4 DDD 4 4 DDD DDD
5 GGG 4 4 DDD DDD
6 ZZZ 4 4 DDD DDD
原始表只有列1至列4,
结果增加列5与列6
类似于EXCEL,
E2的结果是=VLOOKUP(C2:C7,$A$2:$B$7,2,0)
E3 E4....一样
F2的结果是=VLOOKUP(D2:D7,$A$2:$B$7,2,0)
F3 F4....一样.
1 AAA 2 2 BBB BBB
2 BBB 2 2 BBB BBB
3 CCC 2 2 BBB BBB
4 DDD 4 4 DDD DDD
5 GGG 4 4 DDD DDD
6 ZZZ 4 4 DDD DDD
原始表只有列1至列4,
结果增加列5与列6
类似于EXCEL,
E2的结果是=VLOOKUP(C2:C7,$A$2:$B$7,2,0)
E3 E4....一样
F2的结果是=VLOOKUP(D2:D7,$A$2:$B$7,2,0)
F3 F4....一样.
if object_id('tempdb.dbo.#') is not null drop table #
create table #(a int, b varchar(8), c int, d int, e varchar(8), f varchar(8))
insert into #
select 1, 'AAA', 2, 2,null,null union all
select 2, 'BBB', 2, 2,null,null union all
select 3, 'CCC', 2, 2,null,null union all
select 4, 'DDD', 4, 4,null,null union all
select 5, 'GGG', 4, 4,null,null union all
select 6, 'ZZZ', 4, 4,null,nullupdate a set a.e = b.b from # a, # b where a.c = b.a
update a set a.f = b.b from # a, # b where a.d = b.aselect * from #/*
a b c d e f
----------- -------- ----------- ----------- -------- --------
1 AAA 2 2 BBB BBB
2 BBB 2 2 BBB BBB
3 CCC 2 2 BBB BBB
4 DDD 4 4 DDD DDD
5 GGG 4 4 DDD DDD
6 ZZZ 4 4 DDD DDD
*/