cakephp 3.0查询未获取所需结果 [英] cakephp 3.0 query not take required result

查看:72
本文介绍了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

推荐答案

table = TableRegistry :: get('' Mechines');
table = TableRegistry::get('Mechines');


mechines =
mechines =


table-> find() - >选择([' Mechines.id'
' sum' =>
table->find()->select(['Mechines.id', 'sum' =>


这篇关于cakephp 3.0查询未获取所需结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆