SUM()的问题和CakePHP 3的别名(Problems with SUM() and alias with CakePHP 3)

编程入门 行业动态 更新时间:2024-10-12 18:17:59
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']

更多推荐

本文发布于:2023-07-30 14:39:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1338854.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:别名   CakePHP   SUM   Problems   alias

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!