【问题标题】:SUM and Group by field does not retrieve dataSUM 和 Group by 字段不检索数据
【发布时间】:2011-04-08 06:55:00
【问题描述】:

如何从SUM(total) 字段中检索数据?以下代码不会在sum_tot 中产生值:

$bill_receipts = $this->BanquetBillMaster->find('all', 
                    array('conditions' => array('status' => 2),
                          'fields' => array('id', 'total', 
                                  '(SUM(total)) AS sum_tot','booking_master_id'),
                          'group' => 'booking_master_id',
                          'contain' => false));

foreach($bill_receipts as $aa)
{
    echo $aa['BanquetBillMaster']['sum_tot'];
}  

【问题讨论】:

  • 你的表里有这样的字段吗?

标签: cakephp cakephp-1.3 cakephp-1.2


【解决方案1】:

尝试使用debug( $bill_receipts ); 打印数组,sum_tot 字段可能在$aa[ 0 ][ 'sum_tot' ] 中。命名字段位于“正常”结构之外。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-30
    相关资源
    最近更新 更多