开发者

zend framework query

开发者 https://www.devze.com 2023-03-03 22:19 出处:网络
Can someboby please help me on t开发者_如何学JAVAhis query. Basicall i know how to join tables in Zend Framework but what i can\'t figure out is the last part which starts \"AND......\" thats where i

Can someboby please help me on t开发者_如何学JAVAhis query. Basicall i know how to join tables in Zend Framework but what i can't figure out is the last part which starts "AND......" thats where i start my subquery.My query goes like

SELECT requests.`email`,requests.`title`, `request_category`.`request_category_name`,
       `request_route_category`.`department_id`,`departments`.`department_name`
 FROM requests 
 JOIN `request_category` ON requests.`requests_category_id` = request_category.`request_category_id` 
 JOIN `request_route_category` ON `request_category`.`path_id` = `request_route_category`.`path_id` 
 JOIN `departments` ON `request_route_category`.`department_id` = `departments`.`department_id` 
                    AND (SELECT `department_id` 
                         FROM `request_route_category` 
                         WHERE `request_route_category`.`department_id`=`departments`.`department_id` 
                         AND `request_route_category`.`is_complete`=0 
                         LIMIT 1)=7

I have this for now

$select=$this->select()
        ->setIntegrityCheck(false)
        ->from($this->_name,array('reqemail'=>'email','reqcreated'=>'created'))
        ->join('request_category', 'requests.requests_category_id=request_category.request_category_id',array('catpath'=>'path_id','catid'=>'request_category.request_category_id','catname'=>'request_category_name'))
        ->join('request_route_category', 'request_category.path_id=request_route_category.path_id',array())
        ->join('departments','request_route_category.department_id=departments.department_id');


As far as I know you cannot do SubQueries with Join with Zend_DB but you can do that:

$subQuery = $this->select()
        ->setIntegrityCheck(false)
        ->from('request_route_category')
        ->where('request_route_category.department_id = departments.department_id')
        ->where('request_route_category.is_complete = ?', 0)
        ->limit(1);

$sql = $select=$this->select()
    ->setIntegrityCheck(false)
    ->from($this->_name,array('reqemail'=>'email','reqcreated'=>'created'))
    ->join('request_category', 'requests.requests_category_id=request_category.request_category_id',array('catpath'=>'path_id','catid'=>'request_category.request_category_id','catname'=>'request_category_name'))
    ->join('request_route_category', 'request_category.path_id=request_route_category.path_id',array())
    ->join('departments','request_route_category.department_id=departments.department_id AND ('.$subQuery.')=7');
0

精彩评论

暂无评论...
验证码 换一张
取 消