【代码报错】Error: Binder Error: Referenced column "index_code" not found in FROM clause!
由bqkbdhd8创建,最终由small_q 被浏览 15 用户
查询沪深300成分股的收盘价 报错
import dai
# 查询沪深300成分股的收盘价
query = """
SELECT instrument, close
FROM cn_stock_bar1d
WHERE instrument IN (
SELECT instrument
FROM cn_stock_index_component
WHERE index_code = '000300.SH'
) AND date = '2023-01-01' -- 可根据需要调整日期
"""
result_df = dai.query(query).df()
# 输出结果
print(result_df)
InvalidInputException Traceback (most recent call last)
Cell In[16], line 13
3 # 查询沪深300成分股的收盘价
4 query = """
5 SELECT instrument, close
6 FROM cn_stock_bar1d
(...)
11 ) AND date = '2023-01-01' -- 可根据需要调整日期
12 """
---> 13 result_df = dai.query(query).df()
15 # 输出结果
16 print(result_df)
File /var/app/enabled/dai/_telemetry.py:150, in wrapper(*args, **kwargs)
File /var/app/enabled/dai/_functions.py:90, in df(self)
InvalidInputException: Invalid Input Error: Attempting to execute an unsuccessful or closed pending query result
Error: Binder Error: Referenced column "index_code" not found in FROM clause!
Candidate bindings: "cn_stock_bar1d.close"
\