Python / SQL:Pandas是否允许您读入包含多个连接的SQL查询?

时间:2017-02-06 23:23:42

标签: python sql pandas join dataframe

我有一个包含多个表连接的查询,它似乎在MSSQLServer Management Studio上执行没有任何错误,但Pandas返回错误。

"SELECT Ca.LoanAgreementID, Ca.Amount, Ca.TransactionDate, Ca.ContactID, Ca.PaymentType, " \
      "Ca.CashLedgerType, Ct.KeyValue_String, Pt.KeyValue_String, Lo.AutoNumber, Lo.IssueDateFROM CashLedger as Ca " \
      "LEFT JOIN Enum.CashLedgerTypes as Ct " \
      "ON Ca.CashLedgerType = Ct.KeyValue_Int" \
      "LEFT JOIN Enum.PaymentTypes as Pt " \
      "ON Ca.PaymentType = Pt.KeyValue_Int" \
      "LEFT JOIN LoanAgreements as Lo" \
      "ON Ca.LoanAgreementID = Lo.LoanAgreementID"

data = pd.read_sql(sql, connection)

错误如下:

pandas.io.sql.DatabaseError: Execution failed on sql 'SELECT Ca.LoanAgreementID, Ca.Amount, Ca.TransactionDate, Ca.ContactID, Ca.PaymentType, Ca.CashLedgerType, Ct.KeyValue_String, Pt.KeyValue_String, Lo.AutoNumber, Lo.IssueDate FROM CashLedger as Ca LEFT JOIN Enum.CashLedgerTypes as Ct ON Ca.CashLedgerType = Ct.KeyValue_IntLEFT JOIN Enum.PaymentTypes as Pt ON Ca.PaymentType = Pt.KeyValue_IntLEFT JOIN LoanAgreements as LoON Ca.LoanAgreementID = Lo.LoanAgreementID': ('42000', "[42000] [Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near 'Ca'. (102) (SQLExecDirectW)")

0 个答案:

没有答案