SUM()的问题和CakePHP 3的别名(Problems with SUM() and alias with CakePHP 3)
我正在尝试使用SUM进行SELECT但我有一个带有别名的问题。 CakePHP 3在这里使用。
在我的控制器中,我做:
$preparations->find('all', [ 'fields' => ['SUM(Preparations.qty) as sumqty', 'order_id', 'product_id'], 'conditions' => ['order_id IN ' => $ids], 'contain' => ['Products'], 'group' => 'product_id' ]);但我对此的查询是:
SELECT SUM(Preparations.qty) as sumqty AS SUM(`Preparations__qty`) AS `sumqty`, Preparations.order_id AS `Preparations__order_id`, Preparations.product_id AS `Preparations__product_id`SUM()写入两次。 我该如何解决这个问题?
I'm trying to do a SELECT with a SUM but I have a probleme with aliases. CakePHP 3 is used here.
In my controller, I do :
$preparations->find('all', [ 'fields' => ['SUM(Preparations.qty) as sumqty', 'order_id', 'product_id'], 'conditions' => ['order_id IN ' => $ids], 'contain' => ['Products'], 'group' => 'product_id' ]);But the query i have with this is :
SELECT SUM(Preparations.qty) as sumqty AS SUM(`Preparations__qty`) AS `sumqty`, Preparations.order_id AS `Preparations__order_id`, Preparations.product_id AS `Preparations__product_id`SUM() is written twice. How can I resolve this problem ?
最满意答案
尝试这个
'fields' => ['sumqty'=>'SUM(Preparations.qty)', 'order_id', 'product_id']Try this
'fields' => ['sumqty'=>'SUM(Preparations.qty)', 'order_id', 'product_id']更多推荐
发布评论