dongxieting9623
2018-02-06 05:54
浏览 156
已采纳

错误:调用未定义的函数SUM()

using cakephp2

$total = $this->order->find('all', array(
    'fields'     => array(SUM(order.vat)),
    'conditions' => $condition
));

SUM function is not working for me, am geeting error:

Call to undefined function SUM()

图片转代码服务由CSDN问答提供 功能建议

使用cakephp2

  $ total = $ this->  order-> find('all',array(
'fields'=> array(SUM(order.vat)),
'conditions'=> $ condition 
)); 
   
 
 

SUM 函数对我不起作用,我发现错误:

调用undefined 函数SUM()

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • douchen2025 2018-02-06 05:59
    已采纳

    You need to write it like this,

    $total = $this->order->find('all',array(
      'fields'=>array('SUM(order.vat) as total_vat'),
      'conditions'=>$condition
    ));
    

    Add quotes around SUM(order.vat).

    打赏 评论
  • doumu6997 2018-09-12 02:40

    Here is another solution.

    $this->order->virtualFields['total_vat']='SUM(order.vat)';
    
    $total = $this->order->find('all',array(
      'fields'=>array('total_vat'),
      'conditions'=>$condition
    ));
    
    打赏 评论

相关推荐 更多相似问题