Когда я выполняю запрос
/* 1st Join: sec_table and wrds */
SELECT *
FROM sec_table
JOIN wrds
ON sec_table.cik == wrds.cik
and file_date between LINKDT and LINKENDDT
/* 2nd Join: _______ and sdc */
JOIN sdc
ON substr(wrds.cusip,0,7) == sdc.cusip_acquiror
and sdc.dt_announced between wrds.LINKDT and wrds.LINKENDDT
, я получаю сообщение об ошибке, что sdc.dt_announced
не существует, хотя это столбец в sd c.
Код для воспроизведения ошибки
import io
import pandas as pd
import sqlite3
sec_table = pd.read_csv(
io.StringIO(
"""
page,href,file_name,file_date,company_name,cik
1,/Document/0001019056-14-000922/,0001019056-14-000922,2014-07-16,"mktg, inc.",0000886475
1,/Document/0001104659-07-059707/,0001104659-07-059707,2007-08-07,1 800 CONTACTS INC,0001050122
""")
)
wrds = pd.read_csv(
io.StringIO(
"""
GVKEY,LINKDT,LINKENDDT,iid,tic,cusip,conm,cik,conml,naics,sic
1004,1972-04-24,2020-04-22,1,AIR,000361105,AAR CORP,0000001750,AAR Corp,423860.0,5080
1009,1982-01-18,1996-03-13,1,ABSI,000781104,ABS INDUSTRIES INC,0000313368,ABS Industries Inc,3321.0,3460
""")
)
sdc = pd.read_csv(
io.StringIO(
"""
dt_announced,result,cusip_acquiror,cusip_target
1995-01-01,Completed,31687H,03238Y
1995-01-01,Completed,N9643A,03882N
""")
)
conn = sqlite3.connect(":memory:")
sec_table.to_sql('sec_table', conn, index=False)
sdc.to_sql('sdc', conn, index=False)
wrds.to_sql('wrds',conn, index=False)
qry = '''
/* 1st Join: sec_table and wrds */
SELECT *
FROM sec_table
JOIN wrds
ON sec_table.cik == wrds.cik
and file_date between LINKDT and LINKENDDT
/* 2nd Join: _______ and sdc */
JOIN sdc
ON substr(wrds.cusip,0,7) == sdc.cusip_acquiror
and sdc.dt_announced between wrds.LINKDT and wrds.LINKENDDT
'''
pd.read_sql_query(qry, conn)
no such column: sdc.dt_announce