作为zend Framework的初学者,我需要一些帮助来编写一个sql查询。 这是我的查询:
SELECT
COUNT( * ) AS Ouvert , SUBSTRING_INDEX( emails.email_value, '@', -1 ) AS FAI, track_open.open_date
FROM emails, track_open
WHERE emails.email_id = track_open.email_id
AND DATE( open_date ) = CURDATE( )
GROUP BY SUBSTRING_INDEX( emails.email_value, '@', -1 )
这是我的功能,我必须写它:
public function getOpen()
{
$query = $this->select()
->setIntegrityCheck(false)
->from(array('e' => 'emails'))
->join(array('to' => 'track_open'), 'e.email_id = to.email_id')
??????????
$result = $this->fetchAll($query);
if($result)
{
return $result->toArray();
}
return false;
}
因此,如果有人可以举例写这个查询,因为我不知道如何完成它。
答案 0 :(得分:1)
自从我使用Zend_Db已经很长时间了,我无法真正测试代码,但您可以尝试以下方法:
$query = $this->select()
->setIntegrityCheck(false)
->from(array('e' => 'emails'), array(
'Ouvert' => new Zend_Db_Expr('COUNT( * )'),
'FAI' => new Zend_Db_Expr("SUBSTRING_INDEX( emails.email_value, '@', -1 )"),
'track_open.open_date',
))
->join(array('to' => 'track_open'), 'e.email_id = to.email_id')
->where('emails.email_id = track_open.email_id')
->where('DATE( open_date ) = CURDATE( )')
->group(new Zend_Db_Expr("SUBSTRING_INDEX( emails.email_value, '@', -1 )"))