2012-01-20 75 views
0

重現查詢我有這樣的SQL查詢:學說1.2:不能與Doctrine_Query

select * 
from tblapplicant AS a 
WHERE a.napplicantid 
not in (
select napplicantid 
from tblcontract 
where dstart BETWEEN '2011-10-27' AND '2012-01-26' 
OR dend BETWEEN '2011-10-27' AND '2012-01-26') 

而且我想建立這樣的查詢教義1.2:

$Query = Doctrine_Query::create() 
        ->select('a') 
        ->from('tblapplicant a') 
        ->innerJoin('a.tblintermediair i') 
        ->where('i.nintermediairid = ? ', $intermediairid) 
        ->addWhere('a.napplicantid NOT IN (select c.napplicantid from tblcontract c WHERE c.dstart BETWEEN ? AND ? OR c.dend BETWEEN ? AND ?)', array($this->tbljobavailable->getFirst()->dday, $this->tbljobavailable->getLast()->dday, $this->tbljobavailable->getFirst()->dday, $this->tbljobavailable->getLast()->dday)); 

但不知何故,一直在抱怨: 找不到分類c

任何想法?

回答

0

前幾天有過這個問題。

其中一種可能的解決方案是爲tblapplicant表本身添加一對一關係。我不喜歡這個,所以創建了額外的查詢來獲得排除的ID。在你的情況下,將是這樣的:

$notIn = Doctrine_Query::create()->(put your subselect query here)->execute(array(), Doctrine_Core::HYDRATE_SINGLE_SCALAR); 

$Query = Doctrine_Query::create() 
       ->select('a') 
       ->from('tblapplicant a') 
       ->innerJoin('a.tblintermediair i') 
       ->where('i.nintermediairid = ? ', $intermediairid) 
       ->whereNotIn('a.napplicantid', $notIn);