【发布时间】:2021-09-06 12:31:02
【问题描述】:
我想从我的安全和交换表中获取数据。 exchange 中的列是 id、mic、exchange_code,安全表有 id、country、ticker、full_name、exchange_id。我想要两个表中的列(如id, ticker, full_name, country, mic, exchange_code )。我已经在 SQLite 中尝试过这个查询,它在 SQLite 浏览器中运行良好。
SELECT security.id, ticker, security.country, exchange_code AS exchange, mic from security
INNER JOIN exchange ON exchange.id = security.exchange_id;
但是当我在 VS Code 中尝试时,它显示了空数据集。查询是:
connection = sqlite3.connect(config.DB_FILE)
connection.row_factory = sqlite3.Row
cursor = connection.cursor()
cursor.execute("""
SELECT security.id, ticker, security.country, exchange_code AS exchange, mic from security
INNER JOIN exchange ON exchange.id = exchange_id
GROUP BY security.id ORDER BY ticker
""")
rows = cursor.fetchall()
【问题讨论】: