代码如下:
sql = "select to_char(f_date at time zone 'GMT-8', 'YYYY-MM-DD
HH24:MI:SS') as f_date, f_open, f_close, f_high, f_low, f_volume
from choice_kwindminutefinancehistory
INNER JOIN choice_financecode
ON choice_kwindminutefinancehistory.f_code_id=choice_financecode.id
where choice_financecode.f_code = '" + stock + "'
AND f_date >='" + start_date + "' and f_date<='" + end_date + "'"
df = pd.read_sql_query(sql, con=self.engine)
这完全正常,我从查询中获得了一个数据框,但是当我更改SQL时(又添加了两个内部联接),如下所示:
sql = "select to_char(kwm.f_date at time zone 'GMT-8', 'YYYY-MM-DD
HH24:MI:SS') as f_date , kwm.f_open as f_open, kwm.f_close as f_close,
kwm.f_high as f_high, kwm.f_low as f_low, kwm.f_volume as f_volume,
dfh.f_date as pre_date, dfh.f_open as pre_open, dfh.f_close as pre_close,
dfh.f_high as pre_high, dfh.f_low as pre_low, dfh2.f_volume as today_volumn
from choice_kwindminutefinancehistory as kwm
INNER JOIN choice_financecode as fc ON kwm.f_code_id=fc.id
INNER JOIN choice_dailyfinancehistory as dfh ON kwm.f_code_id = dfh.f_code_id
and dfh.f_date = '" + pre_date + "'
INNER JOIN choice_dailyfinancehistory as dfh2 ON kwm.f_code_id = dfh2.f_code_id
and dfh2.f_date = '" + start_date + "'
where fc.f_code = '" + stock + "' AND kwm.f_date >= '" + start_date + "'
and kwm.f_date<='" + end_date + "'"
我得到了一个EMPTY数据框。然后,我在屏幕上打印SQL,将其复制并粘贴到DataGrip,该SQL工作正常,它可以返回行,但是在程序中,使用read_sql_query()
它返回空,我不知道为什么。