要从表的某些列复制到另一个表中的一列的SQL查询

Kle*_*rBH 1 mysql sql-server

我有这种情况

表01

reportID | response1 | response2 | response3 | response4 | response5
1        | aaa       | bbb       | ccc       | ddd       | eee
2        | fff       | ggg       | hhh       | iii       | jjj
3        | lll       | mmm       | nnn       | ooo       | ppp
...
Run Code Online (Sandbox Code Playgroud)

我想将这些数据插入table 02,结果应该是这样的

id | reportID | response
1  | 1        | aaa
2  | 1        | bbb
3  | 1        | ccc
4  | 1        | ddd
5  | 1        | eee
6  | 2        | fff
7  | 2        | ggg
8  | 2        | hhh
9  | 2        | iii
10 | 2        | jjj
11 | 3        | lll
...
Run Code Online (Sandbox Code Playgroud)

我怎么能做到这一点,我试过:

INSERT INTO table02 (reported, response) 
SELECT reportid, reponse1 FROM table01
Run Code Online (Sandbox Code Playgroud)

但这似乎不对.

Table 01包含大约4k行,所以table 2将有大约20k.

这里最好的方法是什么?

我可以创建一个控制台应用程序并从那里执行,但我想从SQL Server Management Studio中执行此操作.

Gor*_*off 7

最简单的方法是使用union all:

insert into table02(reported, response)
    select reportid, reponse1 from table01 union all
    select reportid, reponse2 from table01 union all
    select reportid, reponse3 from table01 union all
    select reportid, reponse4 from table01 union all
    select reportid, reponse5 from table01;
Run Code Online (Sandbox Code Playgroud)