t 语法,用于第 1 行的“GROUP BY bids.item”附近


t syntax to use near 'GROUP BY bids.item' at line 1 in

这是我的查询:

SELECT   bids.item, 
         bids.username, 
         bids.amount, 
         orders.product, 
         orders.status, 
         products.enddate 
FROM     bids, 
         orders, 
         products 
WHERE    bids.username=? 
AND      Now() > products.enddate 
AND      orders.status=0 
ORDER BY bids.amount DESC 
GROUP BY bids.item

警告:PDOStatement::execute(): SQLSTATE[42000]:语法 错误或访问冲突:1064 SQL 语法有错误; 检查与您的 MySQL 服务器版本对应的手册以了解 在 1 行的"GROUP BY bids.item"附近使用的正确语法 C:''xampp''htdocs''auction''application''model''UsersModel.php on 250

编辑,Rizier 感谢您编辑我的帖子,有没有一个线程可以教我如何制作该布局还是我必须手动完成?

Order by应该排在group by之后

WHERE bids.username=? AND NOW() > products.enddate AND orders.status=0 
GROUP BY bids.item
ORDER BY bids.amount DESC 

还要将逗号分隔的旧连接样式更改为正确的inner join语法。它更具可读性。有关INNER JOIN的更多信息,请查看此处

GROUP BY

应该在 ORDER BY 子句之前,如下所示:

SELECT bids.item, bids.username, bids.amount, orders.product, orders.status, products.enddate 
FROM bids,orders,products 
WHERE bids.username=? 
AND NOW() > products.enddate 
AND orders.status=0 
GROUP BY bids.item
ORDER BY bids.amount DESC 

旁注,不鼓励隐式连接,因此您应该明确使用连接,如下所示:

TABLE1 INNER JOIN TABLE2 ON ....