【发布时间】:2021-09-02 09:35:46
【问题描述】:
我正在尝试从交易表中获取每月的金额总和。我在 cakephp 函数下面写了我想要的输出。
public function getLastSixMOnthsExpenses($since_date, $t_type)
{
$query = $this->find()->select([
'month' => $this->find()->func()->monthname([
'created' => 'identifier'
]),
'amount' => $this->find()->func()->sum('Transactions.amount')
])
->where([
'Transactions.created >='=> $since_date->modify('6 months ago')->startOfMonth(),
'Transactions.created <='=> $since_date->endOfMonth(),
'Transactions.transaction_type '=>$t_type
])
->group(['month'])
->order(['Transactions.created'=>'ASC'])
;
return $query;
}
我遇到了错误
Syntax error or access violation: 1055 Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated column 'kjoumaa_kamaljoumaa.Transactions.created' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
不改变sql模式,如何在这里运行group by?
【问题讨论】:
标签: cakephp cakephp-3.x