2012-11-20 68 views
1

我與Zend合作,我不能低於查詢轉換爲zend_db選擇對象格式:轉換複雜的查詢Zend_Db的選擇對象格式

SELECT *,CASE WHEN @score != score THEN @rank := @rank + 1 ELSE @rank END AS rank, 
       @score := score AS dummy_value 
       FROM ( SELECT score,username,ID,firstName,lastName 
       FROM site_members, 
        (SELECT @rank := 0, @score := NULL) AS vars 
        WHERE `status` = 1 AND score > 0 
       ORDER BY score DESC) AS h; 

這樣的:

$select = $this -> db -> select(); 
    $select -> from('site_members', array('COUNT(*) AS count')); 
    $select -> where("ID = ?", $memberID, Zend_Db::INT_TYPE); 
    $row = $this -> db -> fetchRow($select); 
+0

我覺得世界很大,但我不能得到我的答案 –

回答

1

我的工作我的問題,並找到最佳答案:

  $inner_query = $this -> db -> select() -> from('site_members', array('score', 'username', 'ID', 'firstName', 'lastName')) 
           -> from(array("vars"=>new Zend_Db_Expr('(SELECT @rank := 0, @score := NULL)'))) 
           -> where("site_members.status = ?",1) 
           -> where("score > 0") 
           -> order(array("score DESC")); 
      $select = $this -> db -> select(); 
      $select ->from(array("h"=>$inner_query),array(new Zend_Db_Expr('*'), 
          new Zend_Db_Expr('CASE WHEN @score != score THEN @rank := @rank + 1 ELSE @rank END AS rank'), 
          new Zend_Db_Expr('@score := score AS dummy_value')));