我正在尝试使用pyodbc使用来自同一数据库中另一个表中的列的数据来更新列。我试过了:
cursor.execute('''
UPDATE Prospect_SC_Fin_102016
SET Prospect_SC_Fin_102016.Sym_Ky=Symbol_Ref_102016.Sym_Ky
FROM Prospect_SC_Fin_102016
INNER JOIN Symbol_Ref_102016
ON Prospect_SC_Fin_102016.Symbol=Symbol_Ref_102016.Symbol;
''')
con.commit()
cursor.close()
con.close()
并获得“缺少运算符”语法错误。
我也试过了:
cursor.execute('''
UPDATE Prospect_SC_Fin_102016
SET Prospect_SC_Fin_102016.Sym_Ky=(SELECT Sym_Ky
FROM Symbol_Ref_102016 WHERE Symbol IN
(SELECT Symbol FROM Prospect_SC_Fin_102016));
''')
con.commit()
cursor.close()
con.close()
也出错了。这里的逻辑是什么?
答案 0 :(得分:2)
对于Access数据库,您可能希望使用以下格式的查询:
UPDATE Prospect_SC_Fin_102016
INNER JOIN Symbol_Ref_102016
ON Prospect_SC_Fin_102016.Symbol=Symbol_Ref_102016.Symbol
SET Prospect_SC_Fin_102016.Sym_Ky=Symbol_Ref_102016.Sym_Ky