找不到列:“where子句”中有1054个未知列“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'];
}
它试图从哪里获取“总分”列?我认为积分是列,总积分是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);