未找到列:1054未知列' total_points'在' where子句'
protected $ tableGateway;
public function __construct(TableGateway $tableGateway)
{
$this->tableGateway = $tableGateway;
}
public function fetchPoints$transaction_number)
{
$results = $this->tableGateway->select(
array('total_points' => new \Zend\Db\Sql\Expression("sum(points)")),
array('trxnumber' => $transaction_number)
);
return $results[0]['total_points'];
}
它在哪里尝试获取total_points列?我认为点是列,而total_points是alyias。
答案 0 :(得分:1)
select只接受一个参数"其中"。您当前的查询是:
select * from my_table where total_points=sum(points)
女巫正在抛出预期的错误。我是你想要的客人:
select sum(points) as total_points from my_table where trxnumber=X
在这种情况下你应该这样做:
$select = $this->tableGateway->getSql()->select();
$select
->columns(array('total_points' => new \Zend\Db\Sql\Expression("sum(points)")))
->where(array('trxnumber' => $transaction_number));
$result = $this->tableGateway->selectWith($select);