我的查询就像..

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。sku ORDER BY count1 DESC'在第4行


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

最佳答案

您应该按两列分组: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

关于php - 我收到了消息“SQLSTATE [42000]”之类的未捕获的异常“PDOException”错误:语法错误或访问冲突:1064,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/40172839/

10-09 00:42