2010-02-08 58 views
2

很高興能找到這樣一個有天才成員的有用網站。我一直在嘗試爲此SQLITE問題尋找解決方案。谷歌沒有幫助我,除了找到這個網站。 SQL查詢適用於同一數據庫的MSAccess版本。SQLITE INNERJOIN夢魘,需要此解決方案

這是我的SQL語句 - 這對我沒有用。


SELECT Invoices.InvoiceNumber, Invoices.Quantity,Invoices.Code, Invoices.Price,Invoices.Discount, Invoices.InvoiceGrandTotal, Employees.EmployeeName, Customers.CustomerName, Invoices.DateOfInvoice, [price]*[Quantity] AS Total, Customers.Address, Products.Description,Products.Unit 
    FROM Products 
     INNER JOIN (
      ( 
       (Invoices INNER JOIN InvoiceDetails 
        ON Invoices.InvoiceNumber = InvoiceDetails.InvoiceNumber 
       ) INNER JOIN Customers 
        ON Invoices.CustomerID = Customers.CustomerID 
      ) INNER JOIN Employees 
       ON Invoices.UserID = Employees.EmployeeID 
     ) ON Products.Code = InvoiceDetails.Code 
    WHERE (((InvoiceDetails.InvoiceNumber)='10111')); 

的錯誤消息是:Cannot compile Select-Statement: no such column: Invoices.InvoiceNumber

+1

發佈您的創建表腳本。 – 2010-02-08 02:53:44

+0

我找到了解決方案。 Ron Savage的解決方案可以無縫工作。 – Shaamil 2010-02-08 03:46:22

回答

6

這通常只是意味着你拼寫錯誤的列名...檢查發票表,並確保列是InvoiceNumber而不是「Invoice_Number」或類似的東西...

此外,這個que的一個簡單得多的版本ry看起來像這樣..沒有所有奇怪的嵌套:

SELECT 
    Invoices.InvoiceNumber, 
    Invoices.Quantity, 
    Invoices.Code, 
    Invoices.Price, 
    Invoices.Discount, 
    Invoices.InvoiceGrandTotal, 
    Employees.EmployeeName, 
    Customers.CustomerName, 
    Invoices.DateOfInvoice, 
    [price]*[Quantity] AS Total, 
    Customers.Address, 
    Products.Description, 
    Products.Unit 
FROM 
    Invoices 

    JOIN Employees 
     ON Employees.EmployeeID = Invoices.UserID 

    JOIN Customers 
     ON Customers.CustomerID = Invoices.CustomerID 

    JOIN InvoiceDetails 
     ON InvoiceDetails.InvoiceNumber = Invoices.InvoiceNumber 

    JOIN Products 
     ON Products.Code = InvoiceDetails.Code 

WHERE 
    InvoiceDetails.InvoiceNumber = '10111' 
+3

+1將垃圾sql清理成無限可讀性。 – NotMe 2010-02-08 03:09:07

+0

感謝羅恩薩維奇,我欠你很多。你的SQL語句完美工作。 – Shaamil 2010-02-08 03:39:47

+0

很高興能夠幫助! – 2010-02-08 03:40:48

0

我認爲這個問題可能與區分大小寫。除非我錯了,MS Access字段名稱不區分大小寫。在SQLITE表定義中檢查有問題的列名是否正確。