0

我有以下从 Zend_DB_Table_Abstract 扩展的查询

$select = $this->select()
            ->from('expense_details',
             array('SUM(expense_details_amount) AS total'))
        ->where('YEAR(expense_details_date) = ?', '2010')
            ->where('MONTH(expense_details_date) = ?', '01')
            ->where('expense_details_linkemail = ?', 'xxxx@gmail.com');

然而,尽管它的“等效”返回了所需的值,但它返回了一个 NULL 值

SELECT SUM(expense_details_amount) AS total FROM expense_details
WHERE 
YEAR(expense_details_date) = '2010'                     
AND MONTH(expense_details_date) = '01'
AND expense_details_linkemail = 'xxxx@gmail.com'

我上面的 Zend_DB_Table 构造正确吗?

4

2 回答 2

0

在努力寻找解决方案后,我发现了问题所在。

我变了

$value = $this->fetchAll($select); 
$data[] = $value->total; 

$value = $this->fetchRow($select); 
$data[] = $value->total;
于 2010-03-31T14:57:20.290 回答
0

可能有问题的一件事是此字符串文字中的“AS”语句。

array('SUM(expense_details_amount) AS total'))

尝试将其更改为:

array('total' => 'SUM(expense_details_amount)'))

我相信这就是 Zend_Db_Select 处理 AS 的方式。

于 2010-03-31T13:28:57.950 回答