本文介绍了cakephp 3.0查询未获取所需结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的代码
My Code
$table = TableRegistry::get('Mechines');
$mechines = $table->find()->select(['Mechines.id',
'sum' => $table->find()->where(['purchases.mechine_id' => 'Mechines.id'])->func()->sum('purchases.qty')
])->join(['purchases'])->group('Mechines.id')>toArray('assoc');
var_dump($mechines);
die;
重新查询
Requered Query
SELECT m.*,(select sum(p.qty) from purchases p
WHERE p.mechine_id=m.id) AS numberOfFills,
(select sum(p.qty*p.cost) from purchases p
WHERE p.mechine_id=m.id) AS revenue FROM `mechines` m
plsease有人帮我
plsease someone help me
推荐答案
这篇关于cakephp 3.0查询未获取所需结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!