我的TurnoveroverVolumeTable类中有这个查询:
$query = $this->createQuery('tv')
->addSelect('DISTINCT tv.debtor_number')
->addSelect('tv.debtor_name')
->addSelect('tv.country_description')
->addSelect('SUM(tv.turnover_ytd) as tv.turnover_ytd')
->addSelect('tv.currency_description')
->from('TurnoverVolume tv')
->innerJoin('tv.Agent a')
->andWhere('tv.debtor_number = a.debtor_number')
->andWhere('a.agent_number =?', $agent)
->andWhere('tv.period LIKE "' . $year .'%"')
->groupBy('tv.debtor_number');
在检索和显示数据时,我在我的操作类中使用它:
$query = Doctrine_Core::getTable('TurnoverVolume')->getYearTurnover($agent_number, $this->currentYear);
$results = $query->execute();
$turnover_data = array();
foreach ($results as $turnover) {
$turnover_result = array(
'debtor_number' => $turnover['debtor_number'],
'debtor_name' => $turnover['debtor_name'],
'country_description' => $turnover['country_description'],
'turnover_ytd' => $turnover['turnover_ytd'],
'currency_description' => $turnover['currency_description']
);
$turnover_data[] = $turnover_result;
}
我获得的营业额_Ytd的结果是2703,但应该是277450,它只获得了2011年的第一个结果,而不是2011年的总结果。
在Symfony的日志中,我有这个MySQL查询:
SELECT DISTINCT t.company_number AS t__company_number, t.debtor_number AS t__debtor_number, t.period AS t__period, t.debtor_name AS t__debtor_name, t.country_description AS t__country_description, t.currency_description AS t__currency_description, SUM(t.turnover_ytd) AS t__0 FROM turnover_volume t INNER JOIN agent a ON t.debtor_number = a.debtor_number WHERE (t.debtor_number = a.debtor_number AND a.agent_number = '003' AND t.period LIKE "2011%") GROUP BY t.debtor_number
当我直接将其输入MySQL数据库时,这会得到正确的结果。
任何人都可以告诉我我可能做错了吗?
答案 0 :(得分:1)