【问题标题】:Error: Call to undefined function SUM()错误:调用未定义的函数 SUM()
【发布时间】:2018-02-06 05:54:46
【问题描述】:

使用 cakephp2

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

SUM 函数对我不起作用,我遇到错误:

调用未定义函数 SUM()

【问题讨论】:

    标签: php mysql cakephp-2.0


    【解决方案1】:

    你需要这样写,

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

    在SUM(order.vat) 周围添加引号。

    【讨论】:

    • 感谢@Amit Merchant
    【解决方案2】:

    这是另一种解决方案。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-02-16
      • 2014-02-10
      • 2015-07-02
      • 2017-01-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多