我正在使用petl python包对存储在SQL Server数据库中的表执行一些查询。我现在需要在不同数据库上的两个表之间做一个JOIN。
据我所知,函数petl.fromdb只接受一个连接[petl.fromdb(connection, query)]。
有没有办法做我正在用petl做的事情?如果没有,有没有允许我这样做的包?
发布于 2019-12-20 04:39:28
您可以分别从这两个表的数据库中读取它们,然后使用petl.join()连接它们
import petl as etl
# Read both tables
table_a = etl.fromdb(connection_a, 'SELECT * FROM table_a')
table_b = etl.fromdb(connection_b, 'SELECT * FROM table_b')
# Join tables into new table
table_c = etl.join(table_a, table_b, key='id')有关petl.join()的详细信息,请参阅documentation。
https://stackoverflow.com/questions/56715231
复制相似问题