Zend framework 需要帮助将MySQL查询转换为条令查询

Zend framework 需要帮助将MySQL查询转换为条令查询,zend-framework,doctrine,Zend Framework,Doctrine,我正在尝试将以下MySQL查询转换为DQL查询,该查询为我提供了六个月或更长时间没有预约的所有客户机 mysql> select appt.lastDate, clients.firstname, clients.lastname -> from (select max(gapmtDate) as lastDate,gapmtClient from groomappointments group by gapmtClient) as appt ,clients -> where

我正在尝试将以下MySQL查询转换为DQL查询,该查询为我提供了六个月或更长时间没有预约的所有客户机

mysql> select appt.lastDate, clients.firstname, clients.lastname
-> from (select max(gapmtDate) as lastDate,gapmtClient from groomappointments group by gapmtClient) as appt ,clients
-> where date_sub(CURDATE(), INTERVAL 6 MONTH)>lastDate
-> AND clients.clientid = appt.gapmtClient;
我尝试将其与以下内容匹配,但收到一个错误,指出where子句中存在未知列g__0。有人能指出我哪里出了问题吗

public function noappointmentsforsixmonthsAction()
{



  $sixmonths=date('y-m-d',strtotime("-6 months"));

  $q=Doctrine_Query::create()
  ->select('MAX(g.gapmtDate) AS lastDate, c.firstname, c.lastname,g.gapmtClient')
 ->from('PetManager_Model_Groomappointments g')
 ->leftJoin('g.PetManager_Model_Clients c')
 ->where('lastDate <?',$sixmonths)
 ->groupBy('g.gapmtClient');

 .......

}
试试这个:

$q=Doctrine_Query::create()
  ->select('MAX(g.gapmtDate) AS lastDate, c.firstname, c.lastname, g.gapmtClient')
 ->from('PetManager_Model_Groomappointments g')
 ->leftJoin('g.PetManager_Model_Clients c')
 ->where('MAX(g.gapmtDate) < ?', $sixmonths)
 ->groupBy('g.gapmtClient');

我希望这能起作用。

谢谢你的回复,但是MySQL不允许在where子句中使用聚合函数。@Graham你确定吗?我以前在mysql WHERE子句中使用过COUNT。我相信从我所读到的内容来看,这是正确的。这很可能是我查询的格式。我尝试了你的格式,但我得到了一个关于无效使用聚合函数的错误
$q=Doctrine_Query::create()
  ->select('MAX(g.gapmtDate) AS lastDate, c.firstname, c.lastname, g.gapmtClient')
 ->from('PetManager_Model_Groomappointments g')
 ->leftJoin('g.PetManager_Model_Clients c')
 ->where('MAX(g.gapmtDate) < ?', $sixmonths)
 ->groupBy('g.gapmtClient');