找不到列:1054“ where子句”中的未知列“ total_points”
受保护的$ 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列?我以为points是专栏,total_points是alyias。
select仅接受一个参数“ where”。您当前的查询是:
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);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句