将 SQL 查询转换为 Zend DB Select

Convert SQL query to Zend DB Select

如何将此查询转换为 Zend DB 查询

SELECT t1.date, t1.station, t1.ftype, t1.price, t1.currency 
FROM fueling as t1  
INNER JOIN 
(SELECT MAX(t2.date) as maxdate, t2.station, t2.ftype 
FROM fueling as t2   
GROUP BY t2.station, t2.ftype) as t3
ON t1.date=t3.maxdate AND t1.station=t3.station AND t1.ftype=t3.ftype
where t1.station in ('GF112','GF11')
ORDER by t1.station,t1.ftype;

试试下面一个

$subselect = $this->db->select()
        ->from(array('t2'       => 'fueling'),
               array(
                    'maxdate' => 'MAX(t2.date)',
                    'station' => 't2.station',
                    'ftype' => 't2.ftype',
            ));

$select = $this->db->select()
            ->from(array('t1'       => 'fueling'),
                   array(
                        'date' => 't1.date',
                        'station' => 't1.station',
                        'ftype' => 't1.ftype',
                        'price'=>'t1.price',
                        'currency'=>'t1.currency'
                ))
            ->JOIN(array('t3'=>$subselect),'t1.date=t3.maxdate and t1.station=t3.station and t1.ftype=t3.ftype')
            ->Where('t1.station IN (?)', array('GF112','GF11')');

$results = $this->db->query($select)->fetchAll();