[英]I got the error like Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064
My query is like .. 我的查询就像..
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
i got the error like below.. 我收到如下错误。
PHP Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; PHP致命错误:消息“ SQLSTATE [42000]”未捕获的异常“ PDOException”:语法错误或访问冲突:1064 SQL语法有错误; check the manual that corresponds to your MySQL server version for the right syntax to use near ') GROUP BY sfoi. 请查看与您的MySQL服务器版本相对应的手册,以了解在')GROUP BY sfoi附近使用正确的语法。
sku
ORDER BYcount1
DESC' at line 4' 在第4行的sku
ORDER BYcount1
DESC'
Please can you guys explain this ,is there any wrong on my query? 请大家解释一下,我的查询有问题吗?
You should GROUP BY by two columns: oi.sku,oi.product_id 您应该按两列分组: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.