繁体   English   中英

我收到了消息“ SQLSTATE [42000]”之类的未捕获的异常“ PDOException”错误:语法错误或访问冲突:1064

[英]I got the error like Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064

我的查询就像..

SELECT  oi.`sku`,oi.`product_id`, count(*) as `count1`
                FROM `order_item` AS oi RIGHT JOIN `products` AS p ON oi.`product_id` =  p.`entity_id` WHERE oi.`product_id` IN (1234,4556,7854)
                GROUP BY oi.`sku` ORDER BY `count1` DESC

我收到如下错误。

PHP致命错误:消息“ SQLSTATE [42000]”未捕获的异常“ PDOException”:语法错误或访问冲突:1064 SQL语法有错误; 请查看与您的MySQL服务器版本相对应的手册,以了解在')GROUP BY sfoi附近使用正确的语法。 在第4行的sku ORDER BY count1 DESC'

请大家解释一下,我的查询有问题吗?

您应该按两列分组:oi.sku,oi.product_id

SELECT oi.sku,oi.product_id, count(*) as count1 
FROM order_item AS oi 
RIGHT JOIN products AS p ON oi.product_id = p.entity_id 
WHERE oi.product_id IN (1234,4556,7854) 
GROUP BY oi.sku,oi.product_id
ORDER BY count1 DESC

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM