簡體   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