当前位置:  开发笔记 > 数据库 > 正文

SQLITE INNERJOIN梦魇,需要一个解决方案

如何解决《SQLITEINNERJOIN梦魇,需要一个解决方案》经验,为你挑选了1个好方法。

很高兴找到天才成员这样一个有用的网站.我一直试图找到这个SQLITE问题的解决方案.谷歌没有帮助我,除了找到这个网站.SQL查询在同一数据库的MSAccess版本上正常工作.

这是我的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> Ron Savage..:

这通常只是意味着您错误拼写了列名...检查您的发票表并确保该列是InvoiceNumber而不是"Invoice_Number"或类似的东西......

此外,这个查询的一个更简单的版本看起来像这样..没有所有奇怪的嵌套:

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'


+1用于将垃圾sql清理成无限可读的东西.
推荐阅读
php
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有