Python:如何在mysql结果头中包含表前缀
我需要在python中执行以下SQL查询Python:如何在mysql结果头中包含表前缀,python,python-3.x,pandas,sqlalchemy,pymysql,Python,Python 3.x,Pandas,Sqlalchemy,Pymysql,我需要在python中执行以下SQL查询 SELECT table_a.company, table_b.company FROM table_a LEFT JOIN table_b ON table_a.id = table_b.id 但问题是,当我运行代码时(尝试使用pymysql(cursor.execute)和pandas(pd.read\u sql)),它们显示 | company | company | -------------------------
SELECT table_a.company, table_b.company
FROM table_a
LEFT JOIN table_b ON table_a.id = table_b.id
但问题是,当我运行代码时(尝试使用pymysql
(cursor.execute)和pandas
(pd.read\u sql)),它们显示
| company | company |
-----------------------------------
| <some company> | <some company> |
如果有任何帮助,我们将不胜感激。如何
选择表a.company作为“表a.company”…
?我避免使用别名,因为我有时需要使用通配符,比如表a.*
我已经更新了问题。感谢回复如何选择表a.company作为“表a.company”…?我避免使用别名,因为我有时需要使用通配符,比如表a.*
我已经更新了问题。谢谢你的回复
| table_a.company | table_b.company |
---------------------------------------------------
| <some company> | <some company> |
engine = sqlalchemy.create_engine(connection_string)
df = pd.read_sql(text(query), engine, chunksize=chunksize):
print(df)
engine = pymysql.connect(host=host, user=user, password=passw, port=port, db=database)
cursor = engine.cursor()
cursor.execute(query)
result = cursor.fetchmany(chunksize)
num_fields = len(cursor.description)
field_names = [i[0] for i in cursor.description]
df = pd.DataFrame(columns=field_names, data=result)
print(df)