将4列转换为仅2列

时间:2013-11-07 01:49:05

标签: sql sql-server

假设我有下表:

------------------------------------
Name1 | Address1 | Name2 | Address2
------------------------------------
AAA   | Tokyo    | CCCC  | Brazil
EEE   | paris    | FFFF  | Cairo

我需要在sql server中进行查询才能给我两(2)列

----------------
Name  | Address 
----------------
AAA   | Tokyo  
CCCC  | Brazil
EEE   | paris 
FFFF  | Cairo

1 个答案:

答案 0 :(得分:1)

使用UNION ALL:

insert into final_table
  select Name1 name, Address1 address from init_table
  union all
  select Name2 name, Address2 address from init_table;