问题描述:

I have two databases Database1.db and Database2.db. The databases contain tables with matching names and matching columns (and the Primary key is the 'Date' column in both). The only difference between the two is that the entries in Database1 are from 2013 and the entries in Database2 are from 2014. I would like to merge these two databases so that all the 2013 and 2014 data ends up in one table in a third database (let's call it Database3.db).

To be clear, here is what the databases I'm working with currently contain and what I want the third resulting database to contain:

Database1.db:

Table Name: GERMANY_BERLIN

Date Morning Day Evening Night

01.01.2013 0.5 0.2 0.2 0.1

02.01.2013 0.4 0.3 0.1 0.2

...

Database2.db:

Table Name: GERMANY_BERLIN

Date Morning Day Evening Night

01.01.2014 0.6 0.2 0.1 0.1

02.01.2014 0.5 0.2 0.3 0.0

...

I would like to have create a resulting Database3 with the following data:

Database2.db:

Table Name: GERMANY_BERLIN

Date Morning Day Evening Night

01.01.2013 0.5 0.2 0.2 0.1

02.01.2013 0.4 0.3 0.1 0.2

01.01.2014 0.6 0.2 0.1 0.1

02.01.2014 0.5 0.2 0.3 0.0

...

I haven't been able to find anything directly helpful on this online yet (perhaps JOINS could be used somehow? bhttp://www.tutorialspoint.com/sqlite/sqlite_using_joins.htm) so any suggestions would be greatly appreciated!

PS. SQLite has been used to create the existing databases and is the database-related Python library that I'm most familiar with

网友答案:

You can easly export a .db into a csv (How to export sqlite to CSV in Python without being formatted as a list?) and import it again into .db (Importing a CSV file into a sqlite3 database table using Python) for the step 1 just append the result to the same cvs file.

相关阅读:
Top