When I was working on a project, I encountered a scenario where there were two tables with a data volume of around million. Now I want to merge these two tables into one table in the production environment, I originally wanted to use the SQL statement insert into select for implementation. Later I found that this operation was slow because of the computing logic. The approximate table structure is as follows:
Table1
Id tel credits1
Table 2
Id tel credits2 points
The merged table is
Table
Id tel credits points
Credits = credits1 + credits2
The implementation method I used is as follows:
Step 1: Create a view first.
Name: table
The SQL statement is roughly as follows:
Select table2.id, table2.tel, table1.credits1 + table2.credits2 as credits, table2.points from table2 left join table1 on table1.tel = table2.tel
It takes about one day to go online. Find an idle period and close the project.
Step 2: export the data in the view.
Step 3. Rename the view name as table_copy.
Step 4: Create a table with the field id tel credits points
Step 5: import the data in the view to the table.