Php 将SQL查询转换为Zend DB Select
如何将此查询转换为Zend DB查询Php 将SQL查询转换为Zend DB Select,php,mysql,zend-framework,Php,Mysql,Zend Framework,如何将此查询转换为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 A
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();
我对你的子查询做了一点修改,现在一切都好了。多谢各位