cakephp 3.0以两列的形式获取值 [英] cakephp 3.0 get values in two columns as one
本文介绍了cakephp 3.0以两列的形式获取值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试获取两列的倍数作为值,但是在cakephp 3.0中,它给出了错误
I am trying to get multiple of two columns as value but in cakephp 3.0 it given a error
错误:SQLSTATE [42000]:语法错误或访问冲突:1064 SQL语法错误;检查与您的MySQL服务器版本相对应的手册,以获取在'AS(Transactions__amount * PluTransaction FROM
transactions
Transactions
LEF'
$result = $this->Transaction->find('all', array(
'conditions' => [
'Transactions.house_id' => $houseId]
))->join([
[
'alias' => 'PluTransaction',
'table' => 'plu_transactions',
'type' => 'LEFT',
'conditions' => 'PluTransaction.transaction_id = Transactions.id'
]
])->select(['Transactions.id',
'(Transactions.amount * PluTransaction.item_quantity) AS TOTAL',
]);
推荐答案
这不是您定义计算列的方式,请参阅文档
That's not how you define calculated columns, please refer to the docs
Cookbook > Database Access & ORM > Query Builder > Selecting Data
Cookbook>数据库访问& ORM>查询生成器>原始表达式
Cookbook > Database Access & ORM > Query Builder > Raw Expressions
您必须使用key => value
格式分别定义别名和表达式.
You must use the key => value
format to define the alias and the expression separately.
$query = $this->Transaction->find('all', [
'conditions' => [
'Transactions.house_id' => $houseId
]
]);
$query
->select([
'Transactions.id',
'TOTAL' => $query->newExpr('Transactions.amount * PluTransaction.item_quantity')
])
->join(/* ... */)
// ...
这篇关于cakephp 3.0以两列的形式获取值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文