我花了几个小时盯着这段代码。请新鲜的眼睛! 以下是查询的缩写版本:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL
server version for the right syntax to use near
'FROM (`requests` c) JOIN `inventory` d ON `d`.`listing_seq_no` = `c' at line 7
SELECT DISTINCT `c`.`req_id`, `u`.`user_id`, `u`.`org_name`,
CONCAT_WS(' ', `l`.`strength`, `l`.`unit)` as dos, `c`.`quantity` AS quantity1,
(SELECT sum(quantity) from inventory d2
WHERE d2.listing_seq_no = c.listing_seq_no
) as inv_total,
FROM (`requests` c)
JOIN `inventory` d
ON `d`.`listing_seq_no` = `c`.`listing_seq_no`
JOIN `listings` l
ON `l`.`listing_seq_no` = `c`.`listing_seq_no`
编辑:原始CodeIgniter代码段:
$this->db->select ( "c.req_id,
u.user_id,
u.org_name,
l.tradename as name,
CONCAT_WS(' ', l.strength, l.unit) as dos,
);
答案 0 :(得分:5)
此:
CONCAT_WS(' ', `l`.`strength`, `l`.`unit)`
应该是:
CONCAT_WS(' ', `l`.`strength`, `l`.`unit`)
答案 1 :(得分:1)
尝试删除(requests
c)
答案 2 :(得分:0)
这是一个老问题,但您可以使用:
$this->db->select("<your_select_portion>", FALSE);
以避免CI DB类的自动引用功能。我喜欢在带有CI的select语句中使用MySQL函数,这通常可以解决问题(除非你开始使用查询缓存功能,但这是另一个故事)。