2011-07-27 82 views
1

我想這個MySQL查詢轉換爲Zend的格式:翻譯與MySQL查詢子選擇了Zend格式

SELECT count_panne, mvt, nextHost, dtmvt, stat 
FROM (SELECT COUNT(myTable.snMCB) AS count_panne, 
     myTable.mvt, 
     myTable.nextHost, 
     myTable.dtmvt, 
     myTable.stat 
    FROM myDB.myTable myTable 
    WHERE (myTable.dtmvt = calendar__gregorian__today__) 
     AND (myTable.statut = 'NOOK') 
    GROUP BY myTable.snMCB) AS myTempTable 
WHERE count_panne > 2 
ORDER BY count_panne DESC 

(PS:這是一個正確的MySQL的句子modifs)

我跟Zend試了下:

$subSelect = $dbTable->select() 
    ->from($dbTable,array(
     'COUNT(myTable.snMCB) AS count_panne', 
     'myTable.mvt', 
     'myTable.nextHost', 
     'myTable.dtmvt', 
     'myTable.nextHost')) 
    ->where("myTable.dtmvt BETWEEN '$dateDeb' AND '$dateFin'") 
    ->where('myTable.stat = ?', 'NOOK') 
    ->group('myTable.snMCB') 
    ; 

$select = $dbTable->select() 
    ->setIntegrityCheck(false) 
    ->from(new Zend_Db_Expr($subSelect), 
      array('count_panne', 
       'mvt', 
       'nextHost', 
       'dtmvt', 
       'statut')) 
    ->where('count_panne > 2') 
    ->order('count_panne DESC') 
    ; 

它沒有用。

+0

如何,確切地說,沒有工作?始終準確地陳述您期望的和您實際獲得的內容,包括任何錯誤消息。 – outis

回答

1

您是否嘗試過使用DB adpater具有如SQL直接做這個...

$db = $this->getAdapter(); 

$query = $db->prepare("SELECT count_panne, mvt, nextHost, dtmvt, stat 
         FROM (SELECT COUNT(myTable.snMCB) AS count_panne, 
          myTable.mvt, 
          myTable.nextHost, 
          myTable.dtmvt, 
          myTable.stat 
         FROM myDB.myTable myTable 
         WHERE (myTable.dtmvt = calendar__gregorian__today__) 
         AND (myTable.statut = 'NOOK') 
         GROUP BY myTable.snMCB) AS myTempTable 
         WHERE count_panne > 2 
        ORDER BY count_panne DESC"); 

     $query->execute(); 
     return $query->fetchAll(); 
+0

它幫助我很多!非常感謝你:) – Salem

+0

高興有幫助:) – user466764