$query = "select (select count(a.serial_no) from tra2 a where a.model_no = ".$id." and a.flag = cast(3 as character varying) + (select count(a.serial_no) from stk a where a.model_no = ".$id." and a.trans_id is NULL)as qty)";
$result = $this->db->query($query);
return $result->result();
当我运行查询时
ERROR: syntax error at or near "as"
LINE 1: ...ck a where a.model_no = K258 and a.trans_id is NULL)as qty)
答案 0 :(得分:4)
在''
条款中添加WHERE
(引号)。我猜数据类型为VARCHAR
,因此您必须在查询中使用引号
喜欢这个
.... WHERE a.model_no = '" . $id . "' AND ...
答案 1 :(得分:2)
任务结束必须是:
...a.trans_id is NULL)) as qty"
目前你有一些这样的
select (select 1 + 2 as qty)
但你想要
select (select 1 + 2) as qty