我在MYSQL语法中找不到错误:
"SELECT customer.CustomerCode, customer.CustomerName, customer.CustomerAddress, customer.CustomerHandphone, customer,CustomerEmail, product.ProductCode, product.ProductName, product.ProductPrice, orderdetail.OrderCode, orderdetail.ProductCode, orderdetail.ProductPrice, orderlist.OrderCode, orderlist.CustomerCode, orderlist.OrderPrice " +
"FROM customer INNER JOIN (product INNER JOIN (orderlist INNER JOIN(orderdetail INNER JOIN ON orderlist.OrderCode = orderdetail.OrderCode) ON product.ProductCode = orderdetail.ProductCode) ON customer.CustomerCode = orderlist.CustomerCode) " +
"Where orderlist.OrderCode [email protected] " +
"GROUP BY customer.CustomerCode, customer.CustomerName, customer.CustomerAddress, customer.CustomerHandphone, customer,CustomerEmail, product.ProductCode, product.ProductName, product.ProductPrice, orderdetail.OrderCode, orderdetail.ProductCode, orderdetail.ProductPrice, orderlist.OrderCode, orderlist.CustomerCode, orderlist.OrderPrice";"
错误如下 1064 - 您的 SQL 语法有错误;检查与您的 MariaDB 服务器版本相对应的手册,了解在第 1 行 'ON orderlist.OrderCode = orderdetail.OrderCode) ON Product.ProductCode = orderde' 附近使用的正确语法
使用每个
ON
后面的 JOIN
子句编写查询。 这更容易阅读和编写,并且可能是您的问题:
SELECT c.CustomerCode, c.CustomerName, c.CustomerAddress, c.CustomerHandphone, c.CustomerEmail,
p.ProductCode, p.ProductName, p.ProductPrice,
od.OrderCode, od.ProductCode, od.ProductPrice, od.OrderCode,
ol.CustomerCode, ol.OrderPrice " +
FROM orderlist ol INNER JOIN
orderdetail od
ON ol.orderCode = od.OrderCode INNER JOIN
customer c
ON c.CustomerCode = ol.CustomerCode INNER JOIN
product p
ON p.ProductCode = od.ProductCode;
此外,
ORDER BY
似乎没有必要。 通常它会与聚合函数一起使用。 如果您以某种方式获得重复项(这似乎不太可能),请使用 SELECT DISTINCT
。
最后,我不明白这个:
Where ol.OrderCode = @orderdetail.OrderCode
我认为
@orderdetail.OrderCode
不是有效的语法。 如果你想传入一个变量,它看起来更像是:
Where ol.OrderCode = @OrderCode
此 SQL 语法错误是由于
ON
子句放置不当造成的。下面是编写 SQL 查询的更好方法:
SELECT enter code here
customer.CustomerCode,
customer.CustomerName,
customer.CustomerAddress,
customer.CustomerHandphone,
customer.CustomerEmail,
product.ProductCode,
product.ProductName,
product.ProductPrice,
orderdetail.OrderCode,
orderdetail.ProductCode,
orderdetail.ProductPrice,
orderlist.OrderCode,
orderlist.CustomerCode,
orderlist.OrderPrice
FROM
customer
INNER JOIN orderlist ON customer.CustomerCode = orderlist.CustomerCode
INNER JOIN orderdetail ON orderlist.OrderCode = orderdetail.OrderCode
INNER JOIN product ON orderdetail.ProductCode = product.ProductCode
WHERE
orderlist.OrderCode = @orderdetail.OrderCode
GROUP BY
customer.CustomerCode,
customer.CustomerName,
customer.CustomerAddress,
customer.CustomerHandphone,
customer.CustomerEmail,
product.ProductCode,
product.ProductName,
product.ProductPrice,
orderdetail.OrderCode,
orderdetail.ProductCode,
orderdetail.ProductPrice,
orderlist.OrderCode,
orderlist.CustomerCode,
orderlist.OrderPrice;