我在第12行的sql中遇到错误,或者接近命令-count-user_id = user.id。有什么想法吗?谢谢

时间:2015-03-11 03:27:47

标签: mysql sql innodb

SELECT order.date,
   vehicle.year, 
   vehicle.make, 
   vehicle.model, 
   SUM(part.price * order_details.quantity) AS price, 
   order.paid 
FROM vehicle
INNER JOIN user 
   ON user.id = vehicle.user_id
INNER JOIN order 
   ON order.user_id = user.id
INNER JOIN order_details 
   ON order_details.order_id = order.id
INNER JOIN part 
   ON part.id = order_details.part_id

1 个答案:

答案 0 :(得分:0)

ORDER是大多数SQL实现中的保留关键字;你可能需要使用反引号来划分表名。

SELECT `order`.date,
   vehicle.year, 
   vehicle.make, 
   vehicle.model, 
   SUM(part.price * order_details.quantity) AS price, 
   `order`.paid 
FROM vehicle
INNER JOIN user 
   ON user.id = vehicle.user_id
INNER JOIN `order` 
   ON `order`.user_id = user.id
INNER JOIN order_details 
   ON order_details.order_id = `order`.id
INNER JOIN part 
   ON part.id = order_details.part_id