我需要:
- Join 表1 and 表2
- 消除重复
- Keep the originals from 表1
- 一本字典,用来说明旧表中哪个是id,哪个是新id
示例:输出如下所示
PS:事实是,表1源于一个已经在生产中的数据库,我这里的id被用于许多其他表中,所以我不能更改已经在表中的内容,只添加尚未在表中的新数据.但我还需要说明数据的新id是什么.
表1
id name birthdate
1 Goku 1997-12-15
2 Freeza 2000-10-03
3 Vegeta 2003-08-19
表2
id name birthdate
1 Krillin 1983-02-28
2 Roshi 1960-06-07
3 Goku 1997-12-15
4 Freeza 1998-10-10
因此,我需要从中生成以下内容
resulting_表1
id name birthdate
1 Goku 1997-12-15
2 Freeza 2000-10-03
3 Vegeta 2003-08-19
4 Krillin 1983-02-28
5 Roshi 1960-06-07
6 Freeza 1998-10-10
但我还需要一个表格,上面写着一个人在旧桌子上的代码,以及新的代码,这也会,类似于:
从_到_表
id origin new_id
1 table_1 1
2 table_1 2
3 table_1 3
1 table_2 4
2 table_2 5
3 table_2 1
4 table_2 6
我try 了很多方法,现在唯一能做的就是逐行插入,每次都判断两个字段,但这需要花费太多时间,使其不可行.
So far the best way I found consists basically in: Joining the two tables -> Grouping the data and generating new id column -> join the grouped table with the joined two tables to create the 从_到_表 problem is, that approach will change the ids I must not change, and I don't know how to keep those.