我很好奇如何从旧表中的四列复制数据并将数据放入新表中的两列中。我知道我可以将以下两个旧列用于一个新列。但是我如何为很多列做到这一点?
INSERT INTO new_table(new_column_xy)
(
SELECT old_column_x
FROM old_table
UNION ALL
SELECT old_column_y
FROM old_table
)
以下是我要完成的工作。
答案 0 :(得分:5)
只需在您的选择中添加其他列:
INSERT INTO new_table(employee, employee_id)
SELECT pilot, pilot_id
FROM old_table
UNION ALL
SELECT copilot, copilot_id
FROM old_table
答案 1 :(得分:1)
insert into new_table (employee, employee_id) (
select pilot as employee
, pilot_id as employee_id
from old_table
union
select copilot as employee
, copilot_id as employee_id
from old_table
)