我使用下面的代码来总结我所有的钱包余额.
$query = $this->Wallets->find();
$query->select([
'count' => $query->func()->count('id'),
'total_price' => $query->func()->sum('amount')
])
->where(['status' => 4, 'user_id' => $user_id]);
pj($query);
echo $query->total_price;
exit;
Run Code Online (Sandbox Code Playgroud)
出来的 pj($query);
[
{
"count": 2,
"total_price": 700
}
]
Run Code Online (Sandbox Code Playgroud)
在这里,我试图使用下面的查询获得单个单独的价值
echo $query->total_price;
Run Code Online (Sandbox Code Playgroud)
我没有得到它.什么是正确的语法,plz建议我.感谢名单.